| Layui常用总结 | https://blog.csdn.net/libusi001/article/details/100065911 |
springboot项目在上传较大文件时报错:
org.apache.tomcat.util.http.fileupload.FileUploadbase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.二、解决
springBoot项目自带的tomcat对上传的文件大小有默认1M限制,
SpringBoot官方文档中展示:
每个文件的配置最大为1Mb,单次请求的文件的总数不能大于10Mb。
直接在在application.properties配置文件中加入如下代码:
# maxFileSize 单个数据大小 spring.servlet.multipart.maxFileSize = 10MB # maxRequestSize 是总数据大小 spring.servlet.multipart.maxRequestSize=100MB三、相关代码
layui代码:
后台接口示例:
@ResponseBody
@PostMapping(value = "upload")
public Result upload(@RequestParam MultipartFile file) {
log.info("Excel批量上传认证多选题信息!");
...
int i = service.insertBatch(legalizeList);
if (i > 0) {
log.info("批量导入成功");
return Result.success("导入成功", null);
} else {
log.error("批量导入失败!");
return Result.error("导入失败!");
}
} catch (Exception e) {
log.error("数据导入出现异常:{}", e.getMessage());
return Result.error("数据导入失败,请检查数据格式!");
}
}
有用请点赞,养成良好习惯!
疑问、交流、鼓励请留言!



