GithubHelp home page GithubHelp logo

okayhu / ieasyexcel Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 107 KB

基于 Alibaba EasyExcel 的两段式导入入库方案

License: Apache License 2.0

Java 100.00%
java excel excel-import xslx xls poi easyexcel

ieasyexcel's Introduction

IEasyExcel

基于 Alibaba EasyExcel 的两段式导入入库方案

前言

两段式导入入库方案:通过 Excel 导入数据到业务表时,并不会直接的导入业务表。而是通过一个临时表来存储,再将临时表中数据经过清洗、转换等步骤保存至业务表

功能

  • 基于 Bean Validator 注解验证 Excel 字段的正确性 Model
  • 提供了 ReadContextApplyContext,用于获取读 Excel 和 Excel 入库时的上下文
  • 提供了对简单 Excel Head 的验证

快速开始

如果你并未使用过 EasyExcel,请先进行相关的了解

完整的示例,请参考 ieasyexcel-examples

Excel 读

// 构建 Excel 读参数
ExcelReadParam readParam = ExcelReadParam.builder()
    .key(key)
    .excelReader((excelDataList, context) -> {

        // save data to temporary table

    }).build();
// 创建监听器
ExcelReadListener<? extends BasedExcelReadModel> readListener = new ExcelReadListener<>(readParam);
// 读取 Excel
EasyExcel.read(inputStream, EXCEL_BIZ_TYPE.CITY.excelClazz, readListener).sheet().doRead();

Excel 入库

ApplyContextLoader contextLoader = ApplyContextPageLoaderAdapter.getLoader(pageable -> {
    // 分页查询临时表数据
});
// 构建 Excel 入库参数
ExcelApplyParam applyParam = ExcelApplyParam.builder()
    .key(applyKey)
    .contextLoader(contextLoader)
    .excelApplier((data, context) -> {

        // 验证数据合法性并保存到业务表

    }).build();
// 入库执行器
ExcelApplyExecutor<ExcelRow> applyExecutor = new ExcelApplyExecutor<>(applyParam);
// 执行入库
applyExecutor.execute();

ieasyexcel's People

Contributors

braverayy avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

tomdev2008

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.