是否可以在命名查询中访问对象的属性?
这是一个示例域类
class Publication {
String title
String author
Date datePublished
Integer numberOfPages
static namedQueries = {
newerPublications {
//Will throw an error, cannot access a variable declared in a dynamic context.
gt 'datePublished', this.datePublished
}
}
}
最佳答案
您可以执行以下操作:
newerPublications { Publication newerThan ->
gt 'datePublished', newerThan.datePublished
}
然后,您将其称为
Publication.newerPublications(referencePublication).list()
关于grails - 在命名查询中访问对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27447103/