2
有沒有辦法編寫一個自定義的驗證器,根據字段值執行不同的驗證?grails domain class validator +根據字段值設置唯一約束?
例如
class myModel{
A a;
B b;
String prop
static belongsTo:[m:myModel]
constraints{
prop(validator:{
val,obj->
if (obj.a== null){
unique:[b,prop]
}
else{
unique:[a,b,prop]
}
})
}
}
我很困惑這個問題。
在此先感謝
我太新來grails回答你的問題,但我確實發現這可能有助於其他堆棧溢出問題。 http://stackoverflow.com/questions/3447612/grails-custom-validation-query-inside-validation-check-what-happens-while-upd – nathan 2010-09-16 15:37:05