public Boolean checkedEmptyRow(T data) {
Class<?> aClass = data.getClass();
IgnoreEmptyRow annotation = aClass.getAnnotation(IgnoreEmptyRow.class);
if (ObjectUtil.isEmpty(annotation)) {
return false;
}
// 默认为空行
boolean isEmptyRow = true;
for (Field declaredField : aClass.getDeclaredFields()) {
// 允许访问私有字段
declaredField.setAccessible(true);
Object val;
try {
// 从data 对象获取相关字段的值
val = declaredField.get(data);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
// ObjectUtil 支持字符串的空值判断
// 如果为空行因为isEmptyRow 默认为true
if (ObjectUtil.isEmpty(val)) {
continue;
}
if (val instanceof String && ((String) val).trim().length() == 0) {
continue;
}
isEmptyRow = false;
break;
}
return isEmptyRow;
}
通过泛型处理excel空行问题
最新推荐文章于 2025-05-19 11:02:23 发布