1、在配置文件中配置
applicationContext-upload.xml
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
beans
xmlns
=
"http://www.springframework.org/schema/beans"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
>
<
bean
id
=
"multipartResolver"
class
=
"org.springframework.web.multipart.commons.CommonsMultipartResolver"
>
<!--
设置上传文件大小的参数
one of the properties
available; the maximum file size in bytes -->
<
property
name
=
"maxUploadSize"
value
=
"100000"
/>
</
bean
>
</
beans
>
2、在项目中添加
commons-io.jar、commons-fileupload.jar包
或者在maven配置中添加这两个包
<
dependency
>
<
groupId
>
commons-fileupload
</
groupId
>
<
artifactId
>
commons-fileupload
</
artifactId
>
<
version
>
1.2
</
version
>
</
dependency
>
<
dependency
>
<
groupId
>
commons-io
</
groupId
>
<
artifactId
>
commons-io
</
artifactId
>
<
version
>
1.4
</
version
>
</
dependency
>
3、Controller类中的方法