Grails/GORM “in” criteria

怎甘沉沦 提交于 2019-12-09 07:56:58

问题


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 guess the syntax would be something like:

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

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/7773741/grails-gorm-in-criteria

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!