最近开发了一个小项目,因为有前后端交互,便使用springboot进行了开发,其中涉及到excel的下载与上传,现整理出来,下面直接贴代码。
需要引入的jar包
<!-- poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.17</version> </dependency>
1、excel上传jsp页面
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml"
>
<head>
<meta charset="utf-8"/>
<title>处罚平台订单管理</title>
</head>
<!-- BEGIN BODY -->
<body class="childBody">
<!-- BEGIN CONTAINER -->
<div >
<form id="file_form" action="http://localhost:7010/basics/bwList/batchImport"
enctype="multipart/form-data" method="post">
<input type="file" name="file" id="file_input">
<input type="submit" value="导入数据" class="file">
</div>
</form>
</div>
</body>
<!-- END BODY -->
</html>
2、后台处理程序
controller层:
/** * 上传excel数据 * @param file */ @RequestMapping(value = "/batchImport",method = {RequestMethod.POST,RequestMethod.GET}) @ResponseBody public Result batchImport(@RequestParam(value="file") MultipartFile file){