public List<String> validateModel(Integer row, Object obj) {// 验证某一个对象
List<String> list = Lists.newArrayList();
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(obj);// 验证某个对象,也可以只验证其中的某个属性
Iterator<ConstraintViolation<Object>> iter = constraintViolations.iterator();
while (iter.hasNext()) {
String message = iter.next().getMessage();
list.add("单元格[第" + row + "行]格式错误: " + message);
}
return list;
}