Grails criteria query checking `OR` logic

2019-02-27 21:38发布

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条回答
孤傲高冷的网名
2楼-- · 2019-02-27 21:58

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.

查看更多
登录 后发表回答