0
我有我的自定義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
參數。
建築約束違規時可以添加它嗎?
感謝表達變量,已經發現了它。 –