简体   繁体   English

基于Multipart Rest的Java Spring Web服务

[英]Multipart Rest based Java spring web service

Im new to java based web service development. 我是基于Java的Web服务开发的新手。 I need to create a web service which accepts multipart data(ex: zip file). 我需要创建一个接受多部分数据(例如zip文件)的网络服务。 Please help me out how to mention that in the function. 请帮助我在功能中如何提及。

below is my current web service code which is accepting data in the form of json. 下面是我当前的Web服务代码,它接受json形式的数据。

@RequestMapping(value="/workitems/updateData", method=RequestMethod.POST)
@ResponseBody
public Object updateData(@RequestHeader String deviceToken, @RequestBody FormFields[]      
formFields,HttpServletResponse response) throws Exception {

//some code
}

please guide me to how to accept the multipart data in the web service method. 请指导我如何在Web服务方法中接受多部分数据。

thanks in advance. 提前致谢。

@RequestMapping(
value ="/workitems/updateData",method=RequestMethod.POST ,headers="Accept=application/xml, application/json")
    public @ResponseBody
    Object updateData(HttpServletResponse response,@RequestHeader String deviceToken,
            @RequestParam ("file") MultipartFile file) throws Exception {



}

You can support it as above. 您可以如上所述支持它。

You can use normal Upload technique which you use in Servlet - commons-fileupload.jar way. 您可以使用在Servlet中使用的常规上载技术-commons-fileupload.jar方式。

The same code placed in a method inside your controller will work fine. 放置在控制器内部方法中的相同代码可以正常工作。 Make sure you pass HttpServletRequest object to your method. 确保将HttpServletRequest对象传递给您的方法。

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

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