Grails criteria query checking `OR` logic

拜拜、爱过 提交于 2019-12-20 04:23:32

问题


I having grails criteriaQuery where I am checking OR logic againist a single state variable like this:

or {
     eq("status", Status.ONE)
     eq("status", Status.TWO)
     eq("status", Status.THREE)
  }

This code is working fine, My question is, as I am checking OR logic againist a single state, Is there any way to optimize this code like

 eq("status",Status.ONE || Status.TWO || Status.THREE)

Thanks in advance.


回答1:


You can use

'in'( "status", [Status.ONE, Status.TWO, Status.THREE] ) 

Or just

'in'( "status", Status.values() ) 

if Status is an enum with values ONE, TWO & THREE.



来源:https://stackoverflow.com/questions/25768006/grails-criteria-query-checking-or-logic

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