1. 前台代码
导入excel测试 请选择你要导入的excel文件(.xls;.xlsx) //进度条框//上传了多少百分比 0% 导入
2. 后台spring代码
package com.bjpowernode.excel.importExcel.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import java.util.HashMap; import java.util.Map; /** * ClassName:ImportExcel * Package:com.bjpowernode.excel.importExcel.controller * Description: * * @Date:2019/2/25 21:46 * @Author: 郑军 */ @Controller public class ImportExcel { @RequestMapping("/") public String toIndex() { return "index"; } @RequestMapping("/importExcel") @ResponseBody public Map importExcel(@RequestParam("file") MultipartFile file) { Map map = new HashMap<>(); String originalFilename = file.getOriginalFilename(); String fileType = originalFilename.substring(originalFilename.lastIndexOf(".")); if (!".xls".equals(fileType) && !".xlsx".equals(fileType)) { map.put("result", false); map.put("errorMessage", "导入的文件类型有误"); return map; } // 导入的excel数据相关的业务逻辑校验,暂时省略。 map.put("result", true); map.put("errorMessage", ""); return map; } }