SpringMVC使用MultipartFile实现文件上传

SpringMVC 接收 MultipartFile 需要在 spring-mvc.xml 中配置文件解析器

配置

1
2
3
4
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="20971520"/>
    <property name="defaultEncoding" value="UTF-8"/>
</bean>

依赖

1
2
3
4
5
6
7
8
<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
	<groupId>commons-io</groupId>
	<artifactId>commons-io</artifactId>
</dependency>