2017-07-21 5 views
0
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); 

J'ai essayé d'envoyer la liste des objets à Retrofit et MVC printemps a obtenu la sortie ci-dessouscomment envoyer Retrofit Liste <MultipartBody.Part> et l'objet de printemps 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>

ici sont mes codes au printemps comme

@RequestMapping(value = "/", method = RequestMethod.POST) 
@ResponseBody 
public long insertStory(@RequestBody Story story, @RequestPart List<MultipartFile> files) 
     throws Exception { 
    return storyService.insertStory(story, files); 
} 

Que dois-je faire? OTL Je veux obtenir quelques conseils .. s'il vous plaît ^^

Répondre

0

Votre code de ressort est faux.

@RequestMapping(value = "/", method = RequestMethod.POST) 
@ResponseBody 
public long insertStory(@RequestPart("Story") Story story, @RequestPart List<MultipartFile> files) 
     throws Exception { 
    return storyService.insertStory(story, files); 
} 

Modifiez-le comme ceci.