gpt4 book ai didi

grails - 如何从 Web 应用程序中过滤 Groovy/Grails 闭包

转载 作者:行者123 更新时间:2023-12-02 14:44:01 25 4
gpt4 key购买 nike

我有一个 Web 应用程序,它调用一个 grails 应用程序的 db 调用。数据库中充满了通过 groovy 调用返回的产品。我将从数据库中获得的示例对象如下:

class Product{
Boolean is_blue;
Boolean is_round;
Boolean is_alive;
Boolean is_active;
String type;
String name;
}

我想调用 grails 应用程序来过滤这些 bool 值,但我不确定如何通过闭包来实现,这就是我的闭包目前的样子。
def productXML = 
Product.findAll("from Product as p where p.is_active = 1 and p.type = :type
ORDER BY p.${params.sort} ${params.order}",
[type: type], [max: params.max, offset: params.offset])

我最困惑的是如何将这些参数传递给闭包。任何帮助将不胜感激。谢谢。

最佳答案

就像是

def productXML = 
Product.findAll("from Product as p where p.is_active is :active \
and p.type = :type \
ORDER BY p.${params.sort} ${params.order}",
[type: type, active: true],
[max: params.max, offset: params.offset])

或者
def productXML = Product.findAll(params){
type == type && is_active == active
}

是你在找什么?引用 findAll详情。

关于grails - 如何从 Web 应用程序中过滤 Groovy/Grails 闭包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21149691/

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