定义一个约束,其中List
属性是否具有针对列表列表进行验证的值?听起来怪怪的。但你可以做到。有了这个类:
class A {
List hello
static constraint = {
hello inList:[['abc','def','ghi'],[1,2,3],['a','b']]
}
}
你可以在你的控制器中执行此操作:
def instance1 = new A(hello:['abc','def','ghi']).save() //valid
def instance2 = new A(hello:[1,2,3]).save() //valid
def instance3 = new A(hello:['a','b']).save() //valid
def instance4 = new A(hello:['a','b','c']).save() //invalid
def instance5 = new A(hello:[1,2]).save() //invalid
If A
是一个域类,其实例保存在传统数据库中,但是,hello
属性将被删除,因此您需要使用来定义它
static hasMany = [hello: SomeClass]
instead.