- Notifications
You must be signed in to change notification settings - Fork1
基于 Alibaba EasyExcel 的两段式导入入库方案
License
NotificationsYou must be signed in to change notification settings
braverayy/ieasyexcel
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
基于 Alibaba EasyExcel 的两段式导入入库方案
两段式导入入库方案:通过 Excel 导入数据到业务表时,并不会直接的导入业务表。而是通过一个临时表来存储,再将临时表中数据经过清洗、转换等步骤保存至业务表
- 基于
Bean Validator
注解验证 Excel 字段的正确性Model - 提供了ReadContext、ApplyContext,用于获取读 Excel 和 Excel 入库时的上下文
- 提供了对简单 Excel Head 的验证
如果你并未使用过EasyExcel,请先进行相关的了解
完整的示例,请参考ieasyexcel-examples
// 构建 Excel 读参数ExcelReadParamreadParam =ExcelReadParam.builder() .key(key) .excelReader((excelDataList,context) -> {// save data to temporary table }).build();// 创建监听器ExcelReadListener<?extendsBasedExcelReadModel>readListener =newExcelReadListener<>(readParam);// 读取 ExcelEasyExcel.read(inputStream,EXCEL_BIZ_TYPE.CITY.excelClazz,readListener).sheet().doRead();
ApplyContextLoadercontextLoader =ApplyContextPageLoaderAdapter.getLoader(pageable -> {// 分页查询临时表数据});// 构建 Excel 入库参数ExcelApplyParamapplyParam =ExcelApplyParam.builder() .key(applyKey) .contextLoader(contextLoader) .excelApplier((data,context) -> {// 验证数据合法性并保存到业务表 }).build();// 入库执行器ExcelApplyExecutor<ExcelRow>applyExecutor =newExcelApplyExecutor<>(applyParam);// 执行入库applyExecutor.execute();