我有我的自定义validator
,我想为它添加一些错误消息。所以我有下一个代码:
@Override
public boolean isValid(final String label,
final ConstraintValidatorContext constraintValidatorContext) {
constraintValidatorContext.disableDefaultConstraintViolation();
if(label.length() > MAX_LENGTH) {
constraintValidatorContext
.buildConstraintViolationWithTemplate("{error.maxLength}")
.addConstraintViolation();
return false;
}
...
}
我的消息看起来像error.maxLength=You have exceeded max length of {0}
,所以它的参数是maxLength
.
在构建约束违规时可以添加它吗?