1.文件上传
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/marketing/coupon-batch/import/DELAY" method="post" enctype="multipart/form-data">
<input type="file" name="file" value="请选择文件">
<input type="submit" value="上传">
</form>
</body>
</html>
java 运用
@PostMapping("/coupon/import/{operateType}")
public R.Result batchImportCouponOperate(@RequestParam("file")MultipartFile file, @PathVariable String operateType){
return couponOperationService.batchImportCouponOperate( file, operateType );
}
public String batchImportCouponOperate(MultipartFile uploadFile, String operateType) throws IOException {
InputStream inputStream = uploadFile.getInputStream();
String originalFilename = uploadFile.getOriginalFilename();
try {
Map<String, List<List<Object>>> params = ExcelUtils.importExcel(inputStream, originalFilename);
List<List<Object>> datas = params.get("Sheet1");
if (CollectionUtils.isNotEmpty(datas)) {
for (List<Object> param : datas) {
//处理逻辑
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "ok";
}
ExcelUtils :https://blog.csdn.net/qq_36609053/article/details/110648554