代码:static constraints = {
titleStr size:1..120
categoryStr nullable: false,inList:['For Sale', 'For Rent']
}
当categoryStr为For rent时,它将返回错误
答案 0 :(得分:4)
我会使用custom validator进行不区分大小写的检查:
static constraints = {
titleStr size:1..120
categoryStr validator: { ['for sale', 'for rent'].contains(it.toLowerCase()) }
}