需求背景:这个系统只有单条新增的功能,现在需要把excel文件中的数据大量插入进去,人工操作太费时费力,又没有系统源码,没法直接开发导入的功能,只好采用循环调用http接口的方式进行插入。
需要的maven依赖:
<!--读取excel依赖-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!--发送http请求依赖-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.4</version>
</dependency>
代码如下:
import cn.hutool.http.HttpRequest;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
public class HttpTemplate2 {
public static void main(String[] args) {
//读取excel文件;根据你自己需要处理的文件调整
ExcelReader reader = ExcelUtil.getReader("D:\\tmp\\insert.xls");
//startRowIndex=1 第一行不读取直接跳过

最低0.47元/天 解锁文章
5283

被折叠的 条评论
为什么被折叠?



