/**
-
使用hibernate的注解来进行验证
*/
private static Validator validator = Validation
.byProvider(HibernateValidator.class).configure().failFast(true).buildValidatorFactory().getValidator();
public static void validate(T obj) {
Set<ConstraintViolation> constraintViolations = validator.validate(obj);
// 抛出检验异常
if (constraintViolations.size() > 0) {
throw new AppException(“0001”, String.format(“参数校验失败:%s”, constraintViolations.iterator().next().getMessage()));
}
}
}
==========================================================&#