EasyExcel导入
记录摸鱼的一天
技术栈: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导入的更多相关文章
- EasyExcel导入导出
maven依赖 <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel --> <dependency> & ...
- EasyExcel导入工具(SpringMVC下使用)
easyExcel:由阿里巴巴公司开发,由github托管 github上有详细使用文档 github地址:https://github.com/alibaba/easyexcel/blob/mast ...
- java使用户EasyExcel导入导出excel
使用alibab的EasyExce完成导入导出excel 一.准备工作 1.导包 <!-- poi 相关--> <dependency> <groupId>org. ...
- TestLink在线Excel用例转换xml
[原文链接]:https://blog.tecchen.tech ,博文同步发布到博客园. 由于精力有限,对文章的更新可能不能及时同步,请点击上面的原文链接访问最新内容. 欢迎访问我的个人网站:htt ...
- 【Easyexcel】java导入导出超大数据量的xlsx文件 解决方法
解决方法: 使用easyexcel解决超大数据量的导入导出xlsx文件 easyexcel最大支持行数 1048576. 官网地址: https://alibaba-easyexcel.github. ...
- SpringBoot整合easyexcel实现Excel的导入与导出
导出 在一般不管大的或者小的系统中,各家的产品都一样,闲的无聊的时候都喜欢让我们这些程序员导出一些数据出来供他观赏,非说这是必须需求,非做不可,那么我们就只能苦逼的哼哧哼哧的写bug喽. 之前使用PO ...
- easyExcel用于导入导出
1.添加依赖: <!-- 现在已经更新到1.1.2-beta5 --> <dependency> <groupId>com.alibaba</groupId& ...
- EasyExcel实现导入excel
https://blog.csdn.net/rexueqingchun/article/details/91870372 1.pom.xml配置依赖包 <!-- xls格式excel依赖包 -- ...
- Java实现导入导出Excel:POI和EasyExcel
文章与CSDN同步,欢迎访问:https://blog.csdn.net/qq_40280582/article/details/107300081 代码地址:https://gitee.com/il ...
随机推荐
- phpstorm 远程调式 php
https://cloud.tencent.com/developer/article/1561767 超时设置 fastcgi: ``` 1. apache module的情况下: 修改配置文件 h ...
- ABBYY FineReader 15快速转换文档详解
作为一款专业的"PDF编辑器",用户可通过使用ABBYY FineReader 15的"快速转换"功能,将各种格式的一个或多个文件合并PDF文档.Micros ...
- Camtasia快捷键大全
Camtasia是一款专业屏幕录制软件,它能在任何颜色模式下轻松地记录屏幕动作,另外它还具有即时播放和编辑压缩的功能.在生活上应用范围相当的广泛.在实际运用中如果能了解到相关的快捷键知识,相信是一定程 ...
- nginx学习sub_filter模块
用户替换html中的字符 location / { root /opt/app/code/; random_index on; index index.html index.htm; sub_filt ...
- 【数据结构模版】可持久化线段树 && 主席树
浙江集训Day4,从早8:00懵B到晚21:00,只搞懂了可持久化线段树以及主席树的板子.今天只能记个大概,以后详细完善讲解. 可持久化线段树指的是一种基于线段树的可回溯历史状态的数据结构.我们想要保 ...
- Java基础教程——多线程:创建线程
多线程 进程 每一个应用程序在运行时,都会产生至少一个进程(process). 进程是操作系统进行"资源分配和调度"的独立单位. Windows系统的"任务管理器&quo ...
- 使用ssh远程连接命令行系统
1.进入shell窗口 2.ssh+用户名+@+ip 例如:ssh root@39.96.58.107 3.输入密码
- 2020.11最新JAVA环境安装配置
Windows10下java环境配置 更新:2020年11月25日 电脑环境: windows10 64位 一.下载jdk 首先到Oracle网站下载对应操作系统的jdk安装包. https://ww ...
- IDEA社区版(Community)和付费版(UItimate)的区别
比对类型 Ultimate(终极版,付费) Community(社区版,免费) 语言支持 Java Java Groovy Groovy Kotlin Kotlin Scala(通过插件) Scala ...
- Spring Cloud 学习 (九) Spring Security, OAuth2
Spring Security Spring Security 是 Spring Resource 社区的一个安全组件.在安全方面,有两个主要的领域,一是"认证",即你是谁:二是& ...