记录摸鱼的一天

技术栈:spring boot2.x+mybatis plus+easyExcel 2.2.6

生成简单的实体类等等等等

导入easyExcel的依赖

实体类

编写服务层


import com.csepdi.ledger.model.Information;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageInfo; import java.util.List; /**
* <p>
* 服务类
* </p>
*
* @author xiaoWan
* @since 2020-12-10
*/
public interface InformationService extends IService<Information> { void readExcel(List<Information> informationList);
}
package com.csepdi.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csepdi.ledger.model.Information;
import com.csepdi.ledger.mapper.InformationMapper;
import com.csepdi.ledger.service.InformationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; /**
* <p>
* 服务实现类
* </p>
*
* @author xiaoWan
* @since 2020-12-10
*/
@Service
public class InformationServiceImpl extends ServiceImpl<InformationMapper, Information> implements InformationService { @Autowired
InformationService informationService; @Override
public void readExcel(List<Information> informationList) {
informationService.saveBatch(informationList);
}
}

编写监听工具类



import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.csepdi.ledger.model.Information;
import com.csepdi.ledger.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import java.util.ArrayList;
import java.util.List; @Component
@Scope("prototype")
public class ExcelImportUtils extends AnalysisEventListener<Information> { @Autowired
InformationService informationService; List<Information> list = new ArrayList<>(); @Override
public void invoke(Information information, AnalysisContext analysisContext) {
list.add(information);
informationService.readExcel(list);
} @Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}

控制层

    @PostMapping("/importExcel")
public void importExcel(MultipartFile uploadExcel) throws IOException {
//工作簿
ExcelReaderBuilder read = EasyExcel.read(uploadExcel.getInputStream(), Information.class, excelImportUtils);
//工作表
read.sheet().doRead();
}

postman测试

完活

EasyExcel导入的更多相关文章

  1. EasyExcel导入导出

    maven依赖 <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel --> <dependency> & ...

  2. EasyExcel导入工具(SpringMVC下使用)

    easyExcel:由阿里巴巴公司开发,由github托管 github上有详细使用文档 github地址:https://github.com/alibaba/easyexcel/blob/mast ...

  3. java使用户EasyExcel导入导出excel

    使用alibab的EasyExce完成导入导出excel 一.准备工作 1.导包 <!-- poi 相关--> <dependency> <groupId>org. ...

  4. TestLink在线Excel用例转换xml

    [原文链接]:https://blog.tecchen.tech ,博文同步发布到博客园. 由于精力有限,对文章的更新可能不能及时同步,请点击上面的原文链接访问最新内容. 欢迎访问我的个人网站:htt ...

  5. 【Easyexcel】java导入导出超大数据量的xlsx文件 解决方法

    解决方法: 使用easyexcel解决超大数据量的导入导出xlsx文件 easyexcel最大支持行数 1048576. 官网地址: https://alibaba-easyexcel.github. ...

  6. SpringBoot整合easyexcel实现Excel的导入与导出

    导出 在一般不管大的或者小的系统中,各家的产品都一样,闲的无聊的时候都喜欢让我们这些程序员导出一些数据出来供他观赏,非说这是必须需求,非做不可,那么我们就只能苦逼的哼哧哼哧的写bug喽. 之前使用PO ...

  7. easyExcel用于导入导出

    1.添加依赖: <!-- 现在已经更新到1.1.2-beta5 --> <dependency> <groupId>com.alibaba</groupId& ...

  8. EasyExcel实现导入excel

    https://blog.csdn.net/rexueqingchun/article/details/91870372 1.pom.xml配置依赖包 <!-- xls格式excel依赖包 -- ...

  9. Java实现导入导出Excel:POI和EasyExcel

    文章与CSDN同步,欢迎访问:https://blog.csdn.net/qq_40280582/article/details/107300081 代码地址:https://gitee.com/il ...

随机推荐

  1. leetcode133. 克隆图

    给定无向连通图中一个节点的引用,返回该图的深拷贝(克隆).图中的每个节点都包含它的值 val(Int) 和其邻居的列表(list[Node]).示例: 输入:{"$id":&quo ...

  2. 记录一下Comparator的用法

    Collections.sort(res, new Comparator<ArrayList<Integer>>() {             @Override       ...

  3. input[type=file] 样式美化,input上传按钮美化

    <style>.file { position: relative; display: inline-block; background: #D0EEFF; border: 1px sol ...

  4. linux配置tomcat项目包

    安装配置tomcat 操作系统:  centos 7.1 使用模式:命令模式 使用工具:xshell5 .xftp5 注意之前有配置过tomcat需要进行以下4个步骤 1.关闭网管服务 输入命令: 进 ...

  5. 10、Spring Boot分布式

    1.分布式简介  2.Zookeeper和Dubbo  3.zookeeper (1).zookeeper安装 官方文档:https://hub.docker.com/_/zookeeper?tab= ...

  6. JavaSE 学习笔记07丨IO流

    Chapter 13. IO流 13.1 File类 java.io.File类是文件(file)和目录(文件夹)(directory)路径名(path)的抽象表示,主要用于文件和目录的创建.查找和删 ...

  7. http 文件上传

    参考https://www.cnblogs.com/yuwei0911/p/8601542.html

  8. centOs7.5.64之前的操作系统搭建GitLab记录

    GitLab搭建步骤: 1. Install and configure the necessary dependencies (1)yum install curl openssh-server o ...

  9. String.Split()函数 非原创

    我们在上次学习到了 String.Join函数(http://blog.csdn.net/zhvsby/archive/2008/11/28/3404704.aspx),其中用到了String.SPl ...

  10. JZOJ2020年10月5日提高B组反思

    2020年10月5日提高B组反思 T1 考试的时候想简单了 觉得把跟没有攻占的点相连的边留下就可以了 没有考虑到最小 WA&RE 10 T2 没有思路 就直接从中间往后枚举分解处 蜜汁错误 W ...