如下例所示,我们在车库(Garage)类中含有一个汽车列表(carList),可以在这个汽车列表属性上使用@FluentValid注解,表示需要级联到内部Car做onEach验证。 publicclassGarage{@FluentValidate({CarNotExceedLimitValidator.class})@FluentValidprivateList<Car> carList; } 注意,@FluentValid和@FluentValidate两个注解不互相冲突,...
public interface ValidateCallback { void onSuccess(ValidatorElementList validatorElementList); void onFail(ValidatorElementList validatorElementList, List<String> errorMsgs); void onUncaughtException(Validator validator, Exception e, Object target) throws Exception; } ...
ValidatorChain chain = new ValidatorChain(); List<Validator> validators = new ArrayList<Validator>(); validators.add(new CarValidator()); chain.setValidators(validators); Result ret = FluentValidator.checkAll().on(car, chain).doValidate().result(toSimple()); 2.8.2 Annotation-based validation...
DefaultResult{pass=false, notPassList=[DefaultConstraintResult{pass=false, message='name: 值 <null> 不是预期值', value=null, constraint='HasNotNullConstraint', expectValue='', fieldName='name'}], allList=null} IResult 方法说明 返回值实现默认为 DefaultResult,接口 IResult 属性如下: ...
在互联网行业中,基于Java开发的业务类系统,不管是服务端还是客户端,业务逻辑代码的更新往往是非常频繁的,这源于功能的快速迭代特性。在一般公司内部,特...
List cars = request.getCars(); if (CollectionUtils.isEmpty(cars)) { throw BizException(); } for (Car car : cars) { if (car.getSeatCount() < 2) { throw BizException(); } } // do core business logic } 我们可以发现,它不够优雅而且违反一些范式: 1)违反单一职责原则(Single responsibil...
publicResponseexecute(Requestrequest){if(request==null){throwBizException();}Listcars=request.getCars();if(CollectionUtils.isEmpty(cars)){throwBizException();}for(Carcar:cars){if(car.getSeatCount()<2){throwBizException();}}// do core business logic} ...
public interface ValidateCallback { void onSuccess(ValidatorElementList validatorElementList); void onFail(ValidatorElementList validatorElementList, List<String> errorMsgs); void onUncaughtException(Validator validator, Exception e, Object target) throws Exception; } ...
ValidatorChain chain = new ValidatorChain(); List<Validator> validators = new ArrayList<Validator>(); validators.add(new CarValidator()); chain.setValidators(validators); Result ret = FluentValidator.checkAll().on(car, chain).doValidate().result(toSimple()); 2.8.2 Annotation-based validation...
ComplexResultresult=FluentValidator.checkAll() .onEach(list,newStudentValidator()) .doValidate() .result(toComplex()); 4.3 fail fast or fail over 当出现校验失败时,也就是Validator的validate()方法返回了false,那么是继续还是直接退出呢?默认为使用failFast()方法,直接退出,如果你想继续完成所有校验,使用...