2013-08-22 40 views
0

我試圖使用Grails這樣正確使用AND,OR操作符的使用Grails標準

Controller.createCriteria().listDistinct(){ 
and { 
    or{ 
      or{ 
      //condition1 
      //condition2 
      } 
      or{ 
      //condition3 
      //condition4 
      } 

    } 

//condition 5 
} 

} 

createCriteria .criteria建立一個標準,我所得到的是這樣的:

where 
     (
      (
       (
        condition 1 
        or condition2 
       ) 
       or (
        condition 3 
        or condition 4 
       ) 
      ) 
     ) 

應該如何我正確定位子句?

回答

6

您是否嘗試過僅使用一個OR來簡化事情。 我想在這樣的:

and { 
    or{ 
     //condition1 
     //condition2 
     //condition3 
     //condition4 
    } 
    //condition 5 
} 

它會產生更少的複雜SQL