将枚举列表传递给条件
我有一个域 Payment
class Payment {
String name
PaymentType paymentType
}
PaymentType is an ENUM
来搜索特定付款类型的所有付款,这很简单,
def results = Payment.createCriteria.list = {
'in' ('paymentType', PaymentType.valueOf(params.paymentType))
}
当我想针对多种付款类型搜索所有付款时,我该如何处理这种情况,即如果参数。 paymentType 是一个数组吗?
I have a domain Payment
class Payment {
String name
PaymentType paymentType
}
PaymentType is an ENUM
to search all payments of a particular payment type is simple
def results = Payment.createCriteria.list = {
'in' ('paymentType', PaymentType.valueOf(params.paymentType))
}
how can i handle the situation when I want to search all Payments against more then one payment type i.e. if params.paymentType is an array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 paymentType 是一个数组,你可以这样做:
If paymentType is an array, you can do something like this:
@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
@ataylor:
I am not really sure.. but shouldnt it be
def results = Payment.createCriteria().list {
'in' ('paymentType',new params.paymentType.collect{PaymentType.valueOf(it)})
}
or you'll be getting an error
groovy.lang.MissingPropertyException: No such property: params for class: grails.orm.HibernateCriteriaBuilder