gpt4 book ai didi

grails - 关于Grails的新手问题 “createCriteria”

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

我是Grails条件构建器的新手,有人可以解释以下含义吗?

def c = Account.createCriteria()
def results = c {

like("holderFirstName", "Fred%")
and {
between("balance", 500, 1000)
eq("branch", "London")
}
maxResults(10)
order("holderLastName", "desc")
}

是不是意思
  • Select * from account where
    holderFirstName like 'fred%' and
    (balance between 500 and 1000 **and**
    branch='london
    ')
  • Select * from account where
    holderFirstName like 'fred%' and
    (balance between 500 and 1000 **or**
    branch='london
    ')

  • 如果我想一起使用“或”和“与”,该怎么做?

    最佳答案

    您的示例将执行为:

    select * from account 
    where holderFirstName like 'Fred%'
    and balance between 500 and 1000
    and branch = 'London'

    暗示所有顶级条件都必须进行“与”运算。您可以创建与以下相同的条件:
    def c = Account.createCriteria()
    def results = c {
    like("holderFirstName", "Fred%")
    between("balance", 500, 1000)
    eq("branch", "London")
    maxResults(10)
    order("holderLastName", "desc")
    }

    要获取第二个查询,请使用以下条件:
    def c = Account.createCriteria()
    def results = c {
    like("holderFirstName", "Fred%")
    or {
    between("balance", 500, 1000)
    eq("branch", London")
    }
    maxResults(10)
    order("holderLastName", "desc")
    }

    嵌套 and / or闭包以获得更复杂的条件。

    关于grails - 关于Grails的新手问题 “createCriteria”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6222809/

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