简体   繁体   中英

Grails criteria query checking `OR` logic

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM