将枚举列表传递给条件

发布于 2024-10-03 17:40:08 字数 385 浏览 1 评论 0原文

我有一个域 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

(り薆情海 2024-10-10 17:40:08

如果 paymentType 是一个数组,你可以这样做:

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

If paymentType is an array, you can do something like this:

def results = Payment.createCriteria().list {
   'in' ('paymentType', params.paymentType.collect{PaymentType.valueOf(it)})
}
吃兔兔 2024-10-10 17:40:08

@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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文