问题描述:springmvc后台写文件上传接受功能时,使用mutipartfile会报错,提示MultipartResolver没有声明
解决办法:
1.导入文件上传依赖
2.配置bean文件声明MultipartResolver即可
(1).有配置文件的:
<beans :bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
(2).没有配置文件的:
在配置了basePackages的java文件中加入
@Bean(name="multipartResolver")
public MultipartResolver getMultipartResolver(){
CommonsMultipartResolver multipartResolver =new CommonsMultipartResolver();
multipartResolver.setMaxUploadSizePerFile(100000000);//100M
multipartResolver.setDefaultEncoding("UTF-8");
multipartResolver.setResolveLazily(true);
return multipartResolver;
}