在我的应用程序中,我有一个用户域对象,其中包含一些字段,包括密码字段.密码字段是使用JASYPT的加密字符串.出于开发目的,我在启动时创建一个硬编码的新用户.它看起来像这样:
User user = new User(
userId:"user1", userFname:"Joe",
userLname:"Blow", userMinit:"A",
userEmail:"joe@blow.com", userPword:"password").save()
Run Code Online (Sandbox Code Playgroud)
当调用save()时,我相信在后台调用hibernate saveOrUpdate().它将新域对象字段值与现有域对象字段值进行比较,以确定是否应将记录插入到数据库中,或者是否应仅更新已存在的记录.
由于密码字段始终是一个新值,因为JASYPT加密它每次都插入一个新记录.
INSERT INTO USER VALUES(1,'joe@blow.com',
'Joe','user1','Blow','A','','','',
'gIkUvM9b6d5vrEhkKzqKz0U7uxqRpZFhiQrrBTDbKX0=')
INSERT INTO USER VALUES(2,'joe@blow.com',
'Joe','user1','Blow','A','','','',
'yap0S0mCb2CpGngcANpSWoLqlL6SozLYK4WbKYHSVEw=')
Run Code Online (Sandbox Code Playgroud)
这是Domain类:
@Table(name="user")
class User {
String userId
String userFname
String userLname
String userMinit
String userEmail
String userPword
String userMisc1 = ""
String userMisc2 = ""
String userMisc3 = ""
public User(){};
static mapping = {
version false
columns {
userId column:'user_id'
userFname column:'user_fname'
userLname column:'user_lname'
userMinit column:'user_minit'
userEmail column:'user_email'
userPword column:'user_pword'
userMisc1 column:'user_misc1' …Run Code Online (Sandbox Code Playgroud) 我正在为Grails中的域类编写一些命名查询,并且我遇到了阻塞.
给定以下域类:
class Contributor {
// evals is a collection of another domain class
def evals
static namedQueries = {
hasNoEvals {
// Something like this...
evals.size() == 0
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我选择没有Evals的贡献者所需的语法吗?
谢谢.
阅读有关Grails单元测试的文档,我发现了以下内容:
在Grails中,您需要特别注意单元测试和集成测试之间的区别,因为在单元测试中,Grails不会在运行时注入集成测试期间出现的任何动态方法.
有了这个,我假设缺少注入的方法参考:
getBy*,.save()由GORM和Hibernate方法他们在这里谈论的还有其他动态注入的东西吗?
我在一个名为disabled的表中有一个字段,它是一个布尔值.我正在尝试查询false或null但似乎无法使其工作.我尝试了一些事情,很可能是解决方案,但似乎没有用
p = book.createCriteria().list {
'in'('createdUnderAccountCustomerNumber', accountIds)
and {
'in'('createdUnderProfessionalCustomerNumber', professionalCustomerNums)
isNull('disabled')
or {
eq('disabled', false)
}
}
Run Code Online (Sandbox Code Playgroud)
基本上我想要获取在帐户列表下创建的所有书籍以及已禁用设置为false或null的专业人员列表
我正在尝试使用 Grails 2.4.4 组合一个基本的博客应用程序。我的域模型如下:
class Commentable {
String title
static hasMany = [comments:Comment]
}
class Comment extends Commentable {
static belongsTo = [target:Commentable]
}
class Post extends Commentable {
static hasMany = [tags:Tag]
}
class Tag {
String label
static hasMany = [posts:Post]
static belongsTo = Post
}
Run Code Online (Sandbox Code Playgroud)
在 BootStrap.groovy 的 init 方法中,我试图创建一个 Post 和一个 Tag 如下
def post = new Post();
post.setTitle("Post1");
post.save();
def tag = new Tag();
tag.setLabel("Tag1");
tag.save();
tag.addToPost(post);
tag.save();
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误消息:
Message: No signature of method: io.dimitris.blog.Tag.addToPost() …Run Code Online (Sandbox Code Playgroud) 当我在 grails 中编写 .save() 时,它会在数据库表中插入一个新行。但是,不会将数据持久保存在对象中。我尝试过 .save(flush: true) 但没有运气。请帮忙。
谢谢