简体   繁体   English

使用POSTMAN将文件上传到Spring MVC 3.0.x

[英]upload file using POSTMAN to Spring MVC 3.0.x

Be frank and straight. 坦率而直率。

Trying to code a controller on Spring 3.0.6, and testing on it with POSTMAN. 尝试在Spring 3.0.6上编码控制器,并使用POSTMAN对其进行测试。

I found that if I submit file with POSTMAN with config like this: 我发现,如果我使用POSTMAN和config提交文件,如下所示:

{
Headers:{
enctype :multipart/form-data
}
Body:{
(form-data) 'filename': '__file_path__'
}}

And then I cannot handle it in MVC ; 然后我无法在MVC中处理它 ;

While I code MVC like this: 当我像这样编写MVC时:

@RequestMapping(value = "uploadModelXlsFile", method = RequestMethod.POST)
public ResponseEntity<String> uploadModelXlsFile(@RequestParam("file") MultipartFile file)

And then I cannot upload file in POSTMAN. 然后我无法在POSTMAN中上传文件。

In one word, I had not found a way to combine these two component yet. 一言以蔽之,我还没有找到一种将这两个组成部分结合在一起的方法。

So Im looking for help here, please any one get idea help me. 因此,我在这里寻求帮助,请任何有想法的人帮助我。

Thanks you very much reading this post. 非常感谢您阅读这篇文章。 Best wishes and good life. 美好的祝愿和美好的生活。

Ok, its done. 好的,完成了。

on a java project like mine, you need to add some lines to the xml config file. 在像我的Java项目上,您需要向xml配置文件中添加一些行。

Add to file (WEB-INF/spring-mvc.xml) these lines: 将以下行添加到文件(WEB-INF / spring-mvc.xml):

<bean id="multipartResolver"  
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />  
</beans>

And then every thing goes right. 然后,一切都会顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM