fluent-validator
fluent-validator copied to clipboard
参数注解上添加的额外验证器是否应该在最后验证?
FluentValidateInterceptor类fluentValidator.on(arguments[i], addOnValidatorChain)针对参数对象执行校验,基于流式风格,属性间的联合约束校验在单属性校验成功的基础上进行应该比较合理,也更利于简化验证逻辑。
@Override
public boolean validate(ValidatorContext context, Car t) {
// 属性级存在非空校验时,自定义校验可以忽略空值处理
if (t.id < 2) {
context.addErrorMsg(String.format("Seat count is not valid, invalid value=%s", t));
return false;
}
return true;
}
Correct me if my understanding is wrong, your intension is to avoid writing checking NULL when executing validate method on object, right?
Yes, if I have to write checking NULL here, there's no need to to add @FluentValidate({NotNullValidator.class}) on Integer id;.