比如如下注解信息,想要在excel校验的时候放入到异常信息列表中,可以使用工具类获取到该信息
public class EasyExcelValiHelper {
private static Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
public static <T> String validateEntity(T obj) throws NoSuchFieldException, SecurityException {
StringBuilder result = new StringBuilder();
Set<ConstraintViolation<T>> set = validator.validate(obj, Default.class);
if (set != null && set.size() != 0) {
for (ConstraintViolation<T> cv : set) {
Field declaredField = obj.getClass().getDeclaredField(cv.getPropertyPath().toString());
ExcelProperty annotation = declaredField.getAnnotation(ExcelProperty.class);
result.append(cv.getMessage()).append(";");
}
}
return result.toString();
}
}