2010-11-23 42 views
3

我有一個域付款傳遞枚舉清單標準

class Payment { 
    String name 
    PaymentType paymentType 
} 

PaymentType是一個ENUM

來搜索特定的支付類型的所有款項簡單

def results = Payment.createCriteria.list = { 
    'in' ('paymentType', PaymentType.valueOf(params.paymentType)) 
} 

怎麼能我處理這種情況時,我想要搜索所有支付對多個支付類型,即如果params.paymentType是一個數組?

回答

6

如果paymentType是一個數組,你可以這樣做:

def results = Payment.createCriteria().list { 
    'in' ('paymentType', params.paymentType.collect{PaymentType.valueOf(it)}) 
} 
+0

非常感謝ataylor的回覆:) – 2010-11-25 12:07:50

0

@ataylor:

我真的不知道..但不應該說,它是

def results = Payment.createCriteria().list { 'in' ('paymentType',new params.paymentType.collect{PaymentType.valueOf(it)}) }

或者你會得到一個錯誤

groovy.lang.MissingPropertyException: No such property: params for class: grails.orm.HibernateCriteriaBuilder