如何在类级别验证器上返回不同的消息?
界面
public @interface ValidFoo
{
public String message() default "{package.ValidFoo.message}";
}
执行
@Override
public boolean isValid(final Foo foo, final ConstraintValidatorContext context)
{
// check constraint 1
// --> return message "package.ValidFoo.message_constraint1"
// check constraint 2
// --> return message "package.ValidFoo.message_constraint2"
}
ValidationMessages.properties
package.ValidFoo.message=Validation error.
package.ValidFoo.message_constraint1=Validation error 1.
package.ValidFoo.message_constraint2=Validation error 2.