neoremind / fluent-validator

A Java validation framework leveraging fluent interface style and JSR 303 specification
Apache License 2.0
1.02k stars 222 forks source link

参数注解上添加的额外验证器是否应该在最后验证? #31

Open bochuan122 opened 6 years ago

bochuan122 commented 6 years ago

FluentValidateInterceptorfluentValidator.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;
}
neoremind commented 6 years ago

Correct me if my understanding is wrong, your intension is to avoid writing checking NULL when executing validate method on object, right?

bochuan122 commented 6 years ago

Yes, if I have to write checking NULL here, there's no need to to add @FluentValidate({NotNullValidator.class}) on Integer id;.