相关文章
Spring 配置
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<property name="maxUploadSize" value="31457280"/>
<property name="maxInMemorySize" value="40960"/>
</bean>
依赖的组件
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
Java源码
package com.devefx.website.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
@Controller
public class FileUploadController {
@RequestMapping(value="/uploadFile", method=RequestMethod.POST)
public String uploadFile(@RequestParam MultipartFile file) {
file.getInputStream();
file.getOriginalFilename();
file.getSize();
}
}