diff --git a/common/src/main/java/com/jeesite/common/utils/excel/ExcelExport.java b/common/src/main/java/com/jeesite/common/utils/excel/ExcelExport.java index 52ee737a..bc6e3474 100644 --- a/common/src/main/java/com/jeesite/common/utils/excel/ExcelExport.java +++ b/common/src/main/java/com/jeesite/common/utils/excel/ExcelExport.java @@ -39,12 +39,12 @@ import java.util.*; */ public class ExcelExport implements Closeable{ - private static Logger log = LoggerFactory.getLogger(ExcelExport.class); + private static final Logger log = LoggerFactory.getLogger(ExcelExport.class); /** * 工作薄对象 */ - private Workbook wb; + private final Workbook wb; /** * 工作表对象 @@ -69,7 +69,7 @@ public class ExcelExport implements Closeable{ /** * 存储字段类型临时数据 */ - private Map, FieldType> fieldTypes = MapUtils.newHashMap(); + private final Map, FieldType> fieldTypes = MapUtils.newHashMap(); @SuppressWarnings("rawtypes") private static Class dictUtilsClass = null; @@ -194,6 +194,13 @@ public class ExcelExport implements Closeable{ */ public void createSheet(String sheetName, String title, Class cls, Type type, String... groups){ this.annotationList = ListUtils.newArrayList(); + // Get class annotation + ExcelFields cfs = cls.getAnnotation(ExcelFields.class); + if (cfs != null && cfs.value() != null){ + for (ExcelField ef : cfs.value()){ + addAnnotation(annotationList, ef, cfs, type, groups); + } + } // Get constructor annotation Constructor[] cs = cls.getConstructors(); for (Constructor c : cs) { diff --git a/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java b/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java index 4dc78b57..6f388a70 100644 --- a/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java +++ b/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java @@ -41,12 +41,12 @@ import java.util.*; */ public class ExcelImport implements Closeable { - private static Logger log = LoggerFactory.getLogger(ExcelImport.class); + private static final Logger log = LoggerFactory.getLogger(ExcelImport.class); /** * 工作薄对象 */ - private Workbook wb; + private final Workbook wb; /** * 工作表对象 @@ -61,7 +61,7 @@ public class ExcelImport implements Closeable { /** * 存储字段类型临时数据 */ - private Map, FieldType> fieldTypes = MapUtils.newHashMap(); + private final Map, FieldType> fieldTypes = MapUtils.newHashMap(); @SuppressWarnings("rawtypes") private static Class dictUtilsClass = null; @@ -385,6 +385,13 @@ public class ExcelImport implements Closeable { @SuppressWarnings("unchecked") public List getDataList(Class cls, MethodCallback exceptionCallback, String... groups) throws Exception{ List annotationList = ListUtils.newArrayList(); + // Get class annotation + ExcelFields cfs = cls.getAnnotation(ExcelFields.class); + if (cfs != null && cfs.value() != null){ + for (ExcelField ef : cfs.value()){ + addAnnotation(annotationList, ef, cls, Type.IMPORT, groups); + } + } // Get constructor annotation Constructor[] cs = cls.getConstructors(); for (Constructor c : cs) {