我正在尝试将数据从应用程序上传到 Spring 后端服务。
要上传的内容是一个 DataModel,其中包含要创建的对象的数据以及链接到该数据的多个图像。
因此我使用这个方法签名:
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Survey createSurvey(@RequestBody SurveyPostHelper helper, @RequestParam(value="file", required = true) MultipartFile[] images)
我尝试使用注释,但要么我得到一个空白图像数组,要么我的助手是空的。
你会如何解决这个问题?
提前致谢。
我发现这个方法签名可以完成这项工作:
@ResponseBody
public Survey createSurvey(@RequestPart(required=true) SurveyPostHelper helper, @RequestPart(value="file", required = true) final MultipartFile[] images)
对我来说重要的是在客户端应用程序中设置 MimeType。文件 MimeType 应该是image/jpg
和SurveyPostHelper
s to application/json
允许 Spring 解析 json 并将其绑定到我的对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)