捡来的笔记

让Spring支持文件上传功能

转载请注明出处:
http://dyhdyh.com/archives/209.html

支持文件上传所依赖的库

<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload opzione binaria --><dependency>	<groupId>commons-fileupload</groupId>	<artifactId>commons-fileupload</artifactId>	<version>1.2.2</version></dependency>

spring-config.xml的配置需要增加上传的Bean

<!-- 支持上传文件 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> 

Controller里需要用MultipartFile接收

@RequestMapping(value = "/upload, method = RequestMethod.POST)public String uploadSubmit(HttpServletRequest request, Model model, @RequestParam MultipartFile file) {	return "upload";}

 

 

点赞

发表评论