开发环境
Springboot 1.5.2
使用方法,一开始直获取文件为null,不加required = false接口无法访问
@PostMapping("/import")
public void importTest(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request){}
按理说springboot自带MultipartFile 可上传文件,不知道为什么获取不到文件,查阅文件可能存在冲突,故使用其他方式
pom导入apache的方法上传包
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
添加配置,排除掉本身SpringBoot本身@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
@Configuration
@EnableWebMvc
@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
public class TestUploadFileConfig {
@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
return new CommonsMultipartResolver();
}
}
标签:文件,null,SpringBoot,MultipartFile,上传,public
From: https://www.cnblogs.com/pengyifeng/p/17009585.html