From 6b428bcb50e2f90c835ae3f89f96547400fae372 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Sun, 28 Jul 2024 13:24:25 +0800 Subject: [PATCH] =?UTF-8?q?Excel=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=94=AF=E6=8C=81ExcelFields=E6=B3=A8=E8=A7=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=88=B0=E7=B1=BB=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jeesite/common/utils/excel/ExcelExport.java | 13 ++++++++++--- .../com/jeesite/common/utils/excel/ExcelImport.java | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) 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 101577d2..ea704c5a 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) {