将枚举列表传递给标准 [英] Passing Enum List to Criteria

查看:109
本文介绍了将枚举列表传递给标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个域名付款

$ p $ 类别付款{
字符串名称
PaymentType paymentType
}

PaymentType是一个ENUM



搜索特定付款类型的所有付款很简单

  def结果= Payment.createCriteria.list ='('paymentType',PaymentType.valueOf(params.paymentType))
'
'b




当我想要搜索所有支付方式时,如何处理多于一种支付类型的情况,例如params.paymentType是数组? >解决方案

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

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


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?

解决方案

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

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

这篇关于将枚举列表传递给标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆