为嵌入式对象(值对象)加校验

//grails-app/domain
class Person{
   Address address
   static embedded = ['address']
}

//src/groovy
class Address {
    String code
    String street
    String category
    static constraints = {
        detail(nullable:false)
        code(nullable:true,validator:{ String val, Address obj -> 
            if (val == obj.street) {
                return 'Address .code.erre';
            }
        })
    }
}
//可以在i18n中加入`Address .code.erre`进行国际化

你可能感兴趣的:(grails,校验,值对象)