关于 grails “createCriteria” 的新手问题
我是 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 如“fred%”和 (500 和 1000 ** 之间的余额 ** 和 ** branch='london
')从帐户中选择 *,其中 holderFirstName 如“fred%”和 (500 和 1000 之间的余额 **或** Branch='london
')
如果我想同时使用“or”和“and”,我该怎么做?
I am new to Grails criteria builder, can someone please explain what does the following mean?
def c = Account.createCriteria()
def results = c {
like("holderFirstName", "Fred%")
and {
between("balance", 500, 1000)
eq("branch", "London")
}
maxResults(10)
order("holderLastName", "desc")
}
Does it mean
Select * from account where
')
holderFirstName like 'fred%' and
(balance between 500 and 1000 **and**
branch='londonSelect * from account where
')
holderFirstName like 'fred%' and
(balance between 500 and 1000 **or**
branch='london
If i want to use "or" and "and" together how do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的示例将执行为:
所有顶级条件都隐含为“与”在一起。您可以创建相同的条件:
要获得第二个查询,请使用此条件:
嵌套您的
and
/or
闭包以获得更复杂的条件。Your example would execute as:
All top level conditions are implied to be AND'ed together. You could create the same Criteria as:
To get your second query use this Criteria:
Nest your
and
/or
closures for more complex Criteria.你现在的条件就是平衡和分支这两个条件中的“和”。因此,
从帐户中选择*,其中holderFirstName如'fred%'和(500和1000之间的余额和分支='london')是正确的,只是它将最多保存10个结果,并将按以“holderLastName”为降序排列的基础。
要一起使用and和or,您还需要在条件中指定or块,因此您的条件将类似于
此条件平衡条件和分支条件之间的和。还有 prop1 和 prop2 之间的或
Your current criteria means "and" in the two conditions of balance and branch. so
Select * from account where holderFirstName like 'fred%' and (balance between 500 and 1000 and branch='london') is correct, just that it will hold maximum 10 results and will be sorted on the basis of "holderLastName" in descending order.
To use and and or together you also need to specify an or block in criteria, so your criteria will look something like
in this criteria there is an and between balance and branch conditions. and also an or between prop1 and prop2