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 ff9ed47c..9c20dba4 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 @@ -8,6 +8,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -202,6 +203,16 @@ public class ExcelExport implements Closeable{ */ public void createSheet(String sheetName, String title, Class cls, Type type, String... groups){ this.annotationList = ListUtils.newArrayList(); + // Get constructor annotation + Constructor[] cs = cls.getConstructors(); + for (Constructor c : cs) { + ExcelFields efs = c.getAnnotation(ExcelFields.class); + if (efs != null && efs.value() != null){ + for (ExcelField ef : efs.value()){ + addAnnotation(annotationList, ef, c, type, groups); + } + } + } // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs){ 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 69dc42e1..420afa3e 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 @@ -8,6 +8,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -354,6 +355,16 @@ public class ExcelImport implements Closeable { @SuppressWarnings("unchecked") public List getDataList(Class cls, MethodCallback exceptionCallback, String... groups) throws Exception{ List annotationList = ListUtils.newArrayList(); + // Get constructor annotation + Constructor[] cs = cls.getConstructors(); + for (Constructor c : cs) { + ExcelFields efs = c.getAnnotation(ExcelFields.class); + if (efs != null && efs.value() != null){ + for (ExcelField ef : efs.value()){ + addAnnotation(annotationList, ef, c, Type.IMPORT, groups); + } + } + } // Get annotation field Field[] fs = cls.getDeclaredFields(); for (Field f : fs){ diff --git a/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelField.java b/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelField.java index 4e13cdd9..d003aade 100644 --- a/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelField.java +++ b/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelField.java @@ -15,7 +15,7 @@ import com.jeesite.common.utils.excel.fieldtype.FieldType; * @author ThinkGem * @version 2020-3-5 */ -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) +@Target({ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface ExcelField { diff --git a/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelFields.java b/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelFields.java index 4dfedd10..2af861b9 100644 --- a/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelFields.java +++ b/common/src/main/java/com/jeesite/common/utils/excel/annotation/ExcelFields.java @@ -13,7 +13,7 @@ import java.lang.annotation.Target; * @author ThinkGem * @version 2016-11-9 */ -@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR}) @Retention(RetentionPolicy.RUNTIME) public @interface ExcelFields {