gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:42:28 24 4
gpt4 key购买 nike

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

这是一个示例域类

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com