grails - 在命名查询中访问对象的属性

标签 grails gorm

是否可以在命名查询中访问对象的属性?

这是一个示例域类

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/

相关文章:

grails - 如何在不显示参数的情况下获取更干净的网址?

grails - Grails 2.3.8应用程序集成测试失败

spring - Grails-Spring安全性漏洞:使用[dot]绕过URL

grails - 网格单元测试

hibernate - Grails Map <String,Object>导致异常Integer无法转换为String

grails - 在GORM中对可为空的字段进行排序

jquery - 使用 Selenium/Geb 测试 Kendo UI 网格

hibernate - 有条件的Grails

inheritance - 域到域的继承

hibernate - Grails读取GORM映射