|
@@ -374,4 +374,39 @@ public class ImportExcelUtil {
|
|
|
}
|
|
}
|
|
|
return false; // 所有必需字段都不为空
|
|
return false; // 所有必需字段都不为空
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public static List<ImportConfig> getAllFieldCN(Class<?> clazz) {
|
|
|
|
|
+ List<ImportConfig> importConfigs = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ Field[] fields = clazz.getDeclaredFields();
|
|
|
|
|
+
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+ for (int i = 0; i < fields.length; i++) {
|
|
|
|
|
+ Field field = fields[i];
|
|
|
|
|
+ ImportConfig importConfig = new ImportConfig();
|
|
|
|
|
+ field.setAccessible(true); // 访问私有字段
|
|
|
|
|
+ if (field.isAnnotationPresent(Required.class)) {
|
|
|
|
|
+ Required required = field.getAnnotation(Required.class);
|
|
|
|
|
+ Boolean value = required.value();
|
|
|
|
|
+ importConfig.setRequired(value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (field.isAnnotationPresent(ExcelProperty.class)) {
|
|
|
|
|
+ ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
|
|
|
|
|
+ String[] annotationValues = excelProperty.value();
|
|
|
|
|
+ importConfig.setLabel(annotationValues.length > 0 ? annotationValues[0] : "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (field.isAnnotationPresent(ExcelIgnore.class)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ importConfig.setFieldName(field.getName());
|
|
|
|
|
+ importConfig.setSortCode(index++);
|
|
|
|
|
+ importConfig.setWidth(0);
|
|
|
|
|
+ importConfigs.add(importConfig);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return importConfigs;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|