Excel导入导出支持注解写到构造上
This commit is contained in:
@@ -8,6 +8,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
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){
|
public void createSheet(String sheetName, String title, Class<?> cls, Type type, String... groups){
|
||||||
this.annotationList = ListUtils.newArrayList();
|
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
|
// Get annotation field
|
||||||
Field[] fs = cls.getDeclaredFields();
|
Field[] fs = cls.getDeclaredFields();
|
||||||
for (Field f : fs){
|
for (Field f : fs){
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -354,6 +355,16 @@ public class ExcelImport implements Closeable {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <E> List<E> getDataList(Class<E> cls, MethodCallback exceptionCallback, String... groups) throws Exception{
|
public <E> List<E> getDataList(Class<E> cls, MethodCallback exceptionCallback, String... groups) throws Exception{
|
||||||
List<Object[]> annotationList = ListUtils.newArrayList();
|
List<Object[]> 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
|
// Get annotation field
|
||||||
Field[] fs = cls.getDeclaredFields();
|
Field[] fs = cls.getDeclaredFields();
|
||||||
for (Field f : fs){
|
for (Field f : fs){
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import com.jeesite.common.utils.excel.fieldtype.FieldType;
|
|||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2020-3-5
|
* @version 2020-3-5
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
|
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface ExcelField {
|
public @interface ExcelField {
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.lang.annotation.Target;
|
|||||||
* @author ThinkGem
|
* @author ThinkGem
|
||||||
* @version 2016-11-9
|
* @version 2016-11-9
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
|
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface ExcelFields {
|
public @interface ExcelFields {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user