hibernateValidator 升级
hibernateValidator框架返回 ::"字段 不能为null"
public class ValidatorUtils {
public static String validateModel(Object obj) {
StringBuffer buffer = new StringBuffer();
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(obj);
Iterator<ConstraintViolation<Object>> iter = constraintViolations.iterator();
ConstraintViolation<Object> filed;
while (iter.hasNext()) {
filed = iter.next();
String message = filed.getMessage();
Path current = filed.getPropertyPath();
message = current.toString() + " " + message;
buffer.append(message).append(";");
}
return buffer.toString();
}
}