开发者

Grails/GORM "in" criteria

开发者 https://www.devze.com 2023-04-13 07:53 出处:网络
Is it possible to do an \"in\" criteria using the GORM criteria. I\'m looking for the equivalent of the following SQL

Is it possible to do an "in" criteria using the GORM criteria. I'm looking for the equivalent of the following SQL

select * from Person where age in (20,21,22);

If it was possible I g开发者_C百科uess the syntax would be something like:

def results = Person.withCriteria {
    in "age", [20, 21, 22]
}


The Grails createCriteria documentation includes an example of using the in clause:

'in'("holderAge",[18..65]) 
or not{'in'("holderAge",[18..65])}

The documentation includes this note:

Note: 'in' is a groovy reserve word, so it must be escaped by quotes.


Yep, you have it almost exactly right. Just change in to 'in', since in is a keyword in groovy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号