Excel导入导出支持ExcelFields注解添加到类上
This commit is contained in:
@@ -39,12 +39,12 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class ExcelExport implements Closeable{
|
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<Class<? extends FieldType>, FieldType> fieldTypes = MapUtils.newHashMap();
|
private final Map<Class<? extends FieldType>, FieldType> fieldTypes = MapUtils.newHashMap();
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private static Class dictUtilsClass = null;
|
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){
|
public void createSheet(String sheetName, String title, Class<?> cls, Type type, String... groups){
|
||||||
this.annotationList = ListUtils.newArrayList();
|
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
|
// Get constructor annotation
|
||||||
Constructor<?>[] cs = cls.getConstructors();
|
Constructor<?>[] cs = cls.getConstructors();
|
||||||
for (Constructor<?> c : cs) {
|
for (Constructor<?> c : cs) {
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class ExcelImport implements Closeable {
|
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<Class<? extends FieldType>, FieldType> fieldTypes = MapUtils.newHashMap();
|
private final Map<Class<? extends FieldType>, FieldType> fieldTypes = MapUtils.newHashMap();
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
private static Class dictUtilsClass = null;
|
private static Class dictUtilsClass = null;
|
||||||
@@ -385,6 +385,13 @@ 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 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
|
// Get constructor annotation
|
||||||
Constructor<?>[] cs = cls.getConstructors();
|
Constructor<?>[] cs = cls.getConstructors();
|
||||||
for (Constructor<?> c : cs) {
|
for (Constructor<?> c : cs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user