我正在尝试将数据从应用程序上传到spring后端服务。要上传的内容是一个DataModel,其中包含要创建的对象的数据和几个链接到该数据的图像。因此,我使用这个方法签名:
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Survey createSurvey(@RequestBody SurveyPostHelper helper, @RequestParam(value="file", required = true) MultipartFile[] images)我尝试使用注释,但要么得到一个空白图像数组,要么我的helper是空的。你将如何解决这个问题?
提前谢谢。
发布于 2017-02-21 07:43:17
我发现,这个方法签名可以完成这项工作:
@ResponseBody
public Survey createSurvey(@RequestPart(required=true) SurveyPostHelper helper, @RequestPart(value="file", required = true) final MultipartFile[] images)在我的例子中,重要的是在客户端应用程序中设置MimeType。文件MimeType应为image/jpg,SurveyPostHelpers应为application/json,以允许Spring解析json并将其绑定到我的对象。
发布于 2018-03-09 04:35:08
请看为我工作的客户端代码示例图像是我想要保存的文件列表
formData FormData=新的var ();
for (var i = 0; i < images.length ; i++) {
formData.append('images', images[i]);
}
formData.append('adData', new Blob([JSON.stringify(adData)], {
type: "application/json"
}));https://stackoverflow.com/questions/42354139
复制相似问题