除正常使用注解@Validated外还能手动进行校验
public R updateById(@RequestBody @Validated PrdRedBase prdRedBase) {
return R.ok(prdRedBaseService.updateById(prdRedBase));
}
手动触发校验
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<PrdRedBase>> constraintViolations = validator.validate(prdRedBase);
constraintViolations.forEach(error -> {
throw new CheckedException(error.getMessage());
});