MultipartBody.Part.createFormData(contentType, file.getName(), progressRequestBody);// mulitpart
//parameter
String json = gson.toJson(story);
RequestBody requestBody = RequestBody.create(MultipartBody.FORM, json);
parts.add(mulitpart);
//execute ...
Call<Integer> callGetStoryIdByUploadingStoryApi = storyRepository.saveStory(requestBody, parts);
@Multipart
@POST("./")
Call<Integer> saveStory(
@Part("story") RequestBody story,
@Part List<MultipartBody.Part> files);
我试图将改造列表和对象发送到弹簧MVC得到输出
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.32 (Ubuntu) - Error
report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-
family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;
color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;
color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;
background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.
line {height: 1px; background-color: #525D76; border: none;}</style> </head><body>
<h1>HTTP Status 415 - </h1><div class="line"></div><p><b>type</b> Status
report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server
refused this request because the request entity is in a format not supported
by the requested resource for the requested method.</u></p><hr class="line">
<h3>Apache Tomcat/8.0.32 (Ubuntu)</h3></body></html>
&#13;
以下是我在春天的代码
@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseBody
public long insertStory(@RequestBody Story story, @RequestPart List<MultipartFile> files )
throws Exception {
return storyService.insertStory(story, files);
}
我该怎么办? OTL 我想得到一些提示..请^^
答案 0 :(得分:0)
您的Spring代码错误。
@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseBody
public long insertStory(@RequestPart("Story") Story story, @RequestPart List<MultipartFile> files )
throws Exception {
return storyService.insertStory(story, files);
}
像这样改变它。