Springboot中excel文件的上传与下载

最近开发了一个小项目,因为有前后端交互,便使用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){
    
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值