baseService) {
- this.baseService = baseService;
- }
-
- @Override
- public void invoke(T data, AnalysisContext context) {
- cachedDataList.add(data);
- totalCount++;
- if (cachedDataList.size() >= BATCH_COUNT) {
- saveData();
- cachedDataList.clear();
- }
- }
-
- @Override
- public void doAfterAllAnalysed(AnalysisContext context) {
- if (!cachedDataList.isEmpty()) {
- saveData();
- }
- }
-
- private void saveData() {
- baseService.saveBatch(cachedDataList);
- }
-
- public int getTotalCount() {
- return totalCount;
- }
-}
\ No newline at end of file
diff --git a/jeecg-boot-module/jeecg-module-tools/pom.xml b/jeecg-boot-module/jeecg-module-tools/pom.xml
new file mode 100644
index 0000000..a4e216c
--- /dev/null
+++ b/jeecg-boot-module/jeecg-module-tools/pom.xml
@@ -0,0 +1,80 @@
+
+
+ 4.0.0
+
+ org.jeecgframework.boot
+ jeecg-module-tools
+ 1.0.0
+ jar
+
+ jeecg-module-tools
+ 独立 Excel 导入导出工具包 — @ExcelColumn + DictQuery + EasyExcel,零框架耦合
+
+
+ 17
+ UTF-8
+ 4.0.3
+
+
+
+
+
+ com.alibaba
+ easyexcel
+ ${easyexcel.version}
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.12.0
+
+
+
+
+ javax.validation
+ validation-api
+ 2.0.1.Final
+
+
+
+
+ org.hibernate.validator
+ hibernate-validator
+ 6.2.5.Final
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 4.0.1
+ provided
+
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.30
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.11.0
+
+ ${java.version}
+ ${java.version}
+
+
+
+
+
diff --git a/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ColumnMeta.java b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ColumnMeta.java
new file mode 100644
index 0000000..ee7f09b
--- /dev/null
+++ b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ColumnMeta.java
@@ -0,0 +1,11 @@
+package org.jeecg.common.util.excel;
+
+import java.lang.reflect.Field;
+
+/**
+ * @Excel 注解解析后的列元数据
+ */
+public record ColumnMeta(Field field, String name, double width, String format, String[] replace, boolean multiReplace,
+ String numFormat, String groupName, int orderNum, String suffix, String databaseFormat,
+ boolean columnHidden) {
+}
diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ColumnWidthHandler.java b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ColumnWidthHandler.java
similarity index 91%
rename from jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ColumnWidthHandler.java
rename to jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ColumnWidthHandler.java
index 1f92d7b..7afe173 100644
--- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ColumnWidthHandler.java
+++ b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ColumnWidthHandler.java
@@ -34,10 +34,10 @@ public class ColumnWidthHandler extends AbstractColumnWidthStyleStrategy {
}
ColumnMeta meta = columns.get(columnIndex);
Sheet sheet = cell.getSheet();
- if (meta.isColumnHidden()) {
+ if (meta.columnHidden()) {
sheet.setColumnHidden(columnIndex, true);
} else {
- sheet.setColumnWidth(columnIndex, (int) ((meta.getWidth() + 2) * 256));
+ sheet.setColumnWidth(columnIndex, (int) ((meta.width() + 2) * 256));
}
}
}
diff --git a/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/DictQuery.java b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/DictQuery.java
new file mode 100644
index 0000000..916c36d
--- /dev/null
+++ b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/DictQuery.java
@@ -0,0 +1,19 @@
+package org.jeecg.common.util.excel;
+
+/**
+ * 字典查询接口,由调用方实现并注入,
+ * 用于 Excel 导入导出时的字典翻译(如 sex=0 → 男)。
+ */
+@FunctionalInterface
+public interface DictQuery {
+
+ /**
+ * 查询字典键值对映射
+ *
+ * @param dictTable 字典表名(来自 @ExcelColumn.dictTable())
+ * @param dicCode 字典编码字段(来自 @ExcelColumn.dicCode())
+ * @param dicText 字典文本字段(来自 @ExcelColumn.dicText())
+ * @return 格式为 {"text_code", ...} 的数组,如 {"男_0", "女_1"};无结果返回 null 或空数组
+ */
+ String[] query(String dictTable, String dicCode, String dicText);
+}
diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ExcelAnnotationUtils.java b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelAnnotationUtils.java
similarity index 62%
rename from jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ExcelAnnotationUtils.java
rename to jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelAnnotationUtils.java
index 14568d8..09526ba 100644
--- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ExcelAnnotationUtils.java
+++ b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelAnnotationUtils.java
@@ -1,20 +1,11 @@
package org.jeecg.common.util.excel;
import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.context.AnalysisContext;
-import com.alibaba.excel.metadata.data.ReadCellData;
-import com.alibaba.excel.read.listener.ReadListener;
-import com.alibaba.excel.write.handler.WriteHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.jeecg.common.util.SpringContextUtils;
-import org.jeecgframework.dict.service.AutoPoiDictServiceI;
-import org.jeecgframework.poi.excel.annotation.Excel;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
+import org.jeecg.common.util.excel.annotation.ExcelColumn;
import javax.servlet.http.HttpServletResponse;
-import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.io.IOException;
@@ -32,65 +23,70 @@ import java.util.*;
import java.util.function.Consumer;
/**
- * @Excel 注解工具类,用于 EasyExcel 导入导出。
- * 从实体类字段上读取 @Excel 注解,构建 EasyExcel 表头和数据,无需 @ExcelProperty。
+ * @ExcelColumn 注解工具类,用于 EasyExcel 导入导出。
+ * 从实体类字段上读取 @ExcelColumn 注解,构建 EasyExcel 表头和数据,无需 @ExcelProperty。
+ *
+ * 已解耦 jeecgframework,可独立打包复用。调用方通过 {@link DictQuery} 注入字典服务。
*/
@Slf4j
-@Component
public final class ExcelAnnotationUtils {
- private static volatile ExcelAnnotationUtils instance;
- private final Validator validator;
+ private static volatile Validator cachedValidator;
+
+ private ExcelAnnotationUtils() {}
/**
- * 校验错误信息载体:行号 + 错误消息列表(现代 Java Record,1行搞定)
+ * 校验错误信息载体:行号 + 错误消息列表
*/
public record ValidationError(int row, List messages) {}
- @Autowired
- public ExcelAnnotationUtils(Validator validator) {
- this.validator = validator;
- ExcelAnnotationUtils.instance = this;
- log.info("【Excel导入】Spring Validator 成功通过构造器桥接到静态上下文");
- }
-
- private ExcelAnnotationUtils(Validator validator, boolean isBackup) {
- this.validator = validator;
- }
+ // ==================== Validator ====================
+ /**
+ * 获取 Validator 实例(懒加载缓存)。
+ * 若调用方未通过 {@link #setValidator(Validator)} 注入,则自动创建纯 Java Validator。
+ */
public static Validator getValidator() {
- if (instance != null && instance.validator != null) {
- return instance.validator;
+ if (cachedValidator != null) {
+ return cachedValidator;
}
-
synchronized (ExcelAnnotationUtils.class) {
- if (instance == null) {
- log.warn("【Excel导入】未检测到已注入的 Spring 实例,正在启用原生纯 Java Validator 作为安全保底!");
- Validator tempValidator = Validation.buildDefaultValidatorFactory().getValidator();
- instance = new ExcelAnnotationUtils(tempValidator, true);
- return tempValidator;
+ if (cachedValidator == null) {
+ cachedValidator = Validation.buildDefaultValidatorFactory().getValidator();
+ log.info("【Excel工具】已创建默认 Validator(非 Spring 模式)");
}
}
- return instance.validator;
+ return cachedValidator;
}
/**
- * 解析 Class 上带 @Excel 注解的字段,按 orderNum 排序返回列元数据
+ * 注入自定义 Validator(如 Spring 管理的 Validator),需在首次调用前设置。
*/
- public static List parseColumns(Class> clazz) {
+ public static void setValidator(Validator validator) {
+ cachedValidator = validator;
+ }
+
+ // ==================== 注解解析 ====================
+
+ /**
+ * 解析 Class 上带 @ExcelColumn 注解的字段,按 orderNum 排序返回列元数据
+ *
+ * @param clazz 实体类
+ * @param dictQuery 字典查询接口,可为 null(不启用字典翻译)
+ */
+ public static List parseColumns(Class> clazz, DictQuery dictQuery) {
List columns = new ArrayList<>();
- AutoPoiDictServiceI dictService = getDictService();
for (Field field : getAllFields(clazz)) {
- Excel excel = field.getAnnotation(Excel.class);
- if (excel == null) {
+ ExcelColumn col = field.getAnnotation(ExcelColumn.class);
+ if (col == null) {
continue;
}
field.setAccessible(true);
- String[] replace = excel.replace();
- if (dictService != null && (StringUtils.isNotEmpty(excel.dictTable()) || StringUtils.isNotEmpty(excel.dicCode()))) {
- String[] dictReplace = dictService.queryDict(excel.dictTable(), excel.dicCode(), excel.dicText());
+ String[] replace = col.replace();
+ if (dictQuery != null && (StringUtils.isNotEmpty(col.dictTable()) || StringUtils.isNotEmpty(col.dicCode()))) {
+ String[] dictReplace = dictQuery.query(col.dictTable(), col.dicCode(), col.dicText());
if (dictReplace != null && dictReplace.length > 0) {
replace = mergeReplace(replace, dictReplace);
}
@@ -98,41 +94,43 @@ public final class ExcelAnnotationUtils {
columns.add(new ColumnMeta(
field,
- excel.name(),
- excel.width(),
- StringUtils.isNotEmpty(excel.exportFormat()) ? excel.exportFormat() : excel.format(),
+ col.name(),
+ col.width(),
+ StringUtils.isNotEmpty(col.exportFormat()) ? col.exportFormat() : col.format(),
replace,
- excel.multiReplace(),
- excel.numFormat(),
- excel.groupName(),
- parseOrderNum(excel.orderNum()),
- excel.suffix(),
- excel.databaseFormat(),
- excel.isColumnHidden()
+ col.multiReplace(),
+ col.numFormat(),
+ col.groupName(),
+ parseOrderNum(col.orderNum()),
+ col.suffix(),
+ col.databaseFormat(),
+ col.hidden()
));
}
- columns.sort(Comparator.comparingInt(ColumnMeta::getOrderNum));
+ columns.sort(Comparator.comparingInt(ColumnMeta::orderNum));
return columns;
}
+ // ==================== 导出 ====================
+
/**
- * 构建 EasyExcel 多级表头,支持 @Excel.groupName()
+ * 构建 EasyExcel 多级表头,支持 @ExcelColumn.groupName()
*/
public static List> buildHead(List columns) {
- boolean hasGroup = columns.stream().anyMatch(c -> StringUtils.isNotEmpty(c.getGroupName()));
+ boolean hasGroup = columns.stream().anyMatch(c -> StringUtils.isNotEmpty(c.groupName()));
List> head = new ArrayList<>();
for (ColumnMeta col : columns) {
- if (hasGroup && StringUtils.isNotEmpty(col.getGroupName())) {
- head.add(Arrays.asList(col.getGroupName(), col.getName()));
+ if (hasGroup && StringUtils.isNotEmpty(col.groupName())) {
+ head.add(Arrays.asList(col.groupName(), col.name()));
} else {
- head.add(Collections.singletonList(col.getName()));
+ head.add(Collections.singletonList(col.name()));
}
}
return head;
}
/**
- * 将数据列表按 ColumnMeta 转换为 EasyExcel 的行数据,应用字典翻译、日期格式化、值替换等
+ * 将数据列表按 ColumnMeta 转换为 EasyExcel 的行数据
*/
public static List> convertData(List columns, List> dataList) {
List> rows = new ArrayList<>(dataList.size());
@@ -148,10 +146,12 @@ public final class ExcelAnnotationUtils {
/**
* 写出 Excel 的公共入口:设置响应头 + 构建表头 + 写数据
+ *
+ * @param dictQuery 字典查询接口,可为 null
*/
public static void write(HttpServletResponse response, Class> clazz,
- String title, List> data) throws IOException {
- List columns = parseColumns(clazz);
+ String title, List> data, DictQuery dictQuery) throws IOException {
+ List columns = parseColumns(clazz, dictQuery);
List> head = buildHead(columns);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
@@ -161,60 +161,152 @@ public final class ExcelAnnotationUtils {
EasyExcel.write(response.getOutputStream())
.head(head)
- .registerWriteHandler(new ColumnWidthHandler(columns)) // 这里保持自适应宽度
+ .registerWriteHandler(new ColumnWidthHandler(columns))
.sheet(title)
.doWrite(convertData(columns, data));
}
- // ---- 私有辅助方法 ----
+ // ==================== 导入 ====================
+
+ /**
+ * 从 Excel 输入流分批导入数据,基于 @ExcelColumn 注解读取列配置。
+ *
+ * @param dictQuery 字典查询接口,可为 null(不启用字典翻译)
+ */
+ public static int read(InputStream inputStream, Class clazz,
+ Consumer> batchHandler, int batchSize,
+ Consumer> errorHandler,
+ DictQuery dictQuery) {
+
+ List columns = parseColumns(clazz, dictQuery);
+
+ Map nameToCol = new LinkedHashMap<>();
+ Map displayToCode = new LinkedHashMap<>();
+
+ for (ColumnMeta col : columns) {
+ nameToCol.put(col.name(), col);
+ buildReverseReplace(col.replace(), displayToCode);
+ }
+
+ ExcelImportListener listener = new ExcelImportListener<>(
+ clazz, batchSize, nameToCol, displayToCode, batchHandler, errorHandler
+ );
+
+ EasyExcel.read(inputStream, listener).sheet().doRead();
+
+ return listener.getSuccessCount();
+ }
+
+ // ==================== 内部辅助方法 ====================
+
+ static boolean isValidDictDisplay(String[] replace, String value) {
+ for (String s : replace) {
+ String[] arr = s.split("_");
+ if (arr.length >= 2 && arr[0].equals(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ static void setFieldValue(ColumnMeta col, Object obj, String value,
+ Map displayToCode) throws Exception {
+ Field field = col.field();
+ Class> type = field.getType();
+
+ String resolved = displayToCode.getOrDefault(value, value);
+
+ if (type == String.class) {
+ field.set(obj, resolved);
+ return;
+ }
+ try {
+ if (type == Integer.class || type == int.class) {
+ field.set(obj, Integer.valueOf(resolved));
+ } else if (type == Long.class || type == long.class) {
+ field.set(obj, Long.valueOf(resolved));
+ } else if (type == Double.class || type == double.class) {
+ field.set(obj, Double.valueOf(resolved));
+ } else if (type == BigDecimal.class) {
+ field.set(obj, new BigDecimal(resolved));
+ } else if (type == Boolean.class || type == boolean.class) {
+ field.set(obj, Boolean.valueOf(resolved));
+ } else if (type == Date.class) {
+ String format = StringUtils.isNotEmpty(col.databaseFormat()) ? col.databaseFormat() : col.format();
+ if (StringUtils.isNotEmpty(format)) {
+ field.set(obj, new SimpleDateFormat(format).parse(resolved));
+ }
+ } else if (type == LocalDateTime.class) {
+ String format = col.format();
+ if (StringUtils.isNotEmpty(format)) {
+ field.set(obj, LocalDateTime.parse(resolved, DateTimeFormatter.ofPattern(format)));
+ }
+ } else if (type == LocalDate.class) {
+ String format = col.format();
+ if (StringUtils.isNotEmpty(format)) {
+ field.set(obj, LocalDate.parse(resolved, DateTimeFormatter.ofPattern(format)));
+ }
+ } else if (type == Float.class || type == float.class) {
+ field.set(obj, Float.valueOf(resolved));
+ } else if (type == Short.class || type == short.class) {
+ field.set(obj, Short.valueOf(resolved));
+ } else {
+ field.set(obj, resolved);
+ }
+ } catch (NumberFormatException e) {
+ log.warn("【Excel导入】字段值类型转换失败, field: {}, value: {}", field.getName(), resolved);
+ }
+ }
+
+ // ---- 私有方法 ----
private static Object getCellValue(ColumnMeta col, Object obj) {
try {
- Object value = col.getField().get(obj);
+ Object value = col.field().get(obj);
if (value == null || "".equals(value)) {
return "";
}
- if (StringUtils.isNotEmpty(col.getFormat())) {
+ if (StringUtils.isNotEmpty(col.format())) {
value = formatDate(value, col);
}
String strValue = value.toString();
- if (col.getReplace() != null && col.getReplace().length > 0) {
- strValue = col.isMultiReplace()
- ? multiReplaceValue(col.getReplace(), strValue)
- : replaceValue(col.getReplace(), strValue);
+ if (col.replace() != null && col.replace().length > 0) {
+ strValue = col.multiReplace()
+ ? multiReplaceValue(col.replace(), strValue)
+ : replaceValue(col.replace(), strValue);
}
- if (StringUtils.isNotEmpty(col.getNumFormat()) && value instanceof Number) {
- strValue = new DecimalFormat(col.getNumFormat()).format(value);
+ if (StringUtils.isNotEmpty(col.numFormat()) && value instanceof Number) {
+ strValue = new DecimalFormat(col.numFormat()).format(value);
}
- if (StringUtils.isNotEmpty(col.getSuffix())) {
- strValue = strValue + col.getSuffix();
+ if (StringUtils.isNotEmpty(col.suffix())) {
+ strValue = strValue + col.suffix();
}
return strValue;
} catch (Exception e) {
- log.error("获取单元格值失败, field: {}, row: {}", col.getField().getName(), obj, e);
+ log.error("获取单元格值失败, field: {}, row: {}", col.field().getName(), obj, e);
return "";
}
}
private static Object formatDate(Object value, ColumnMeta col) throws Exception {
if (value instanceof Date) {
- return new SimpleDateFormat(col.getFormat()).format((Date) value);
+ return new SimpleDateFormat(col.format()).format((Date) value);
}
if (value instanceof LocalDateTime) {
- return ((LocalDateTime) value).format(DateTimeFormatter.ofPattern(col.getFormat()));
+ return ((LocalDateTime) value).format(DateTimeFormatter.ofPattern(col.format()));
}
if (value instanceof LocalDate) {
- return ((LocalDate) value).format(DateTimeFormatter.ofPattern(col.getFormat()));
+ return ((LocalDate) value).format(DateTimeFormatter.ofPattern(col.format()));
}
- if (value instanceof String && StringUtils.isNotEmpty(col.getDatabaseFormat())) {
- Date parsed = new SimpleDateFormat(col.getDatabaseFormat()).parse((String) value);
- return new SimpleDateFormat(col.getFormat()).format(parsed);
+ if (value instanceof String && StringUtils.isNotEmpty(col.databaseFormat())) {
+ Date parsed = new SimpleDateFormat(col.databaseFormat()).parse((String) value);
+ return new SimpleDateFormat(col.format()).format(parsed);
}
return value;
}
@@ -255,54 +347,6 @@ public final class ExcelAnnotationUtils {
}
}
- private static AutoPoiDictServiceI getDictService() {
- try {
- return SpringContextUtils.getBean(AutoPoiDictServiceI.class);
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * 从 Excel 输入流分批导入数据,基于 @Excel 注解读取列配置。
- */
- public static int read(InputStream inputStream, Class clazz,
- Consumer> batchHandler, int batchSize,
- Consumer> errorHandler) {
-
- // 1. 职责一:解析注解元数据,准备基础映射表
- List columns = parseColumns(clazz);
-
- Map nameToCol = new LinkedHashMap<>();
- Map displayToCode = new LinkedHashMap<>();
-
- for (ColumnMeta col : columns) {
- nameToCol.put(col.getName(), col);
- buildReverseReplace(col.getReplace(), displayToCode);
- }
-
- // 2. 职责二:实例化专属的流式解析校验监听器
- ExcelImportListener listener = new ExcelImportListener<>(
- clazz, batchSize, nameToCol, displayToCode, batchHandler, errorHandler
- );
-
- // 3. 职责三:交由 EasyExcel 引擎启动
- EasyExcel.read(inputStream, listener).sheet().doRead();
-
- // 4. 返回结果
- return listener.getSuccessCount();
- }
-
- static boolean isValidDictDisplay(String[] replace, String value) {
- for (String s : replace) {
- String[] arr = s.split("_");
- if (arr.length >= 2 && arr[0].equals(value)) {
- return true;
- }
- }
- return false;
- }
-
private static void buildReverseReplace(String[] replace, Map displayToCode) {
if (replace == null || replace.length == 0) {
return;
@@ -315,55 +359,6 @@ public final class ExcelAnnotationUtils {
}
}
- static void setFieldValue(ColumnMeta col, Object obj, String value,
- Map displayToCode) throws Exception {
- Field field = col.getField();
- Class> type = field.getType();
-
- String resolved = displayToCode.getOrDefault(value, value);
-
- if (type == String.class) {
- field.set(obj, resolved);
- return;
- }
- try {
- if (type == Integer.class || type == int.class) {
- field.set(obj, Integer.valueOf(resolved));
- } else if (type == Long.class || type == long.class) {
- field.set(obj, Long.valueOf(resolved));
- } else if (type == Double.class || type == double.class) {
- field.set(obj, Double.valueOf(resolved));
- } else if (type == BigDecimal.class) {
- field.set(obj, new BigDecimal(resolved));
- } else if (type == Boolean.class || type == boolean.class) {
- field.set(obj, Boolean.valueOf(resolved));
- } else if (type == Date.class) {
- String format = StringUtils.isNotEmpty(col.getDatabaseFormat()) ? col.getDatabaseFormat() : col.getFormat();
- if (StringUtils.isNotEmpty(format)) {
- field.set(obj, new SimpleDateFormat(format).parse(resolved));
- }
- } else if (type == LocalDateTime.class) {
- String format = col.getFormat();
- if (StringUtils.isNotEmpty(format)) {
- field.set(obj, LocalDateTime.parse(resolved, DateTimeFormatter.ofPattern(format)));
- }
- } else if (type == LocalDate.class) {
- String format = col.getFormat();
- if (StringUtils.isNotEmpty(format)) {
- field.set(obj, LocalDate.parse(resolved, DateTimeFormatter.ofPattern(format)));
- }
- } else if (type == Float.class || type == float.class) {
- field.set(obj, Float.valueOf(resolved));
- } else if (type == Short.class || type == short.class) {
- field.set(obj, Short.valueOf(resolved));
- } else {
- field.set(obj, resolved);
- }
- } catch (NumberFormatException e) {
- log.warn("【Excel导入】字段值类型转换失败, field: {}, value: {}", field.getName(), resolved);
- }
- }
-
private static List getAllFields(Class> clazz) {
List fields = new ArrayList<>();
Class> current = clazz;
@@ -373,4 +368,4 @@ public final class ExcelAnnotationUtils {
}
return fields;
}
-}
\ No newline at end of file
+}
diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java
similarity index 82%
rename from jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java
rename to jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java
index 0af665e..30f348f 100644
--- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java
+++ b/jeecg-boot-module/jeecg-module-tools/src/main/java/org/jeecg/common/util/excel/ExcelImportListener.java
@@ -68,8 +68,8 @@ public class ExcelImportListener implements ReadListener