fluent-validator icon indicating copy to clipboard operation
fluent-validator copied to clipboard

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

Open bochuan122 opened this issue 7 years ago • 2 comments

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;
}

bochuan122 avatar Feb 02 '18 13:02 bochuan122

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

neoremind avatar Feb 03 '18 10:02 neoremind

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

bochuan122 avatar Feb 04 '18 06:02 bochuan122