2017-04-25 27 views
0

我很想發送像CommonsMultipartFile和一個Java對象的請求。我構建的控制器如下。 在表單數據上傳的圖片(1截圖),在車身原料(第二截圖)我發送用戶object.This是我done.Can:如何發送請求上傳包含java對象的文件,如@RequestParam CommonsMultipartFile文件,@ RequestBody用戶userDetailsId?

public @ResponseBody Response upload(@RequestParam CommonsMultipartFile userPhoto, @RequestBody UserDetails userDetailsId, 
      @RequestParam String authCode) 
//method impl 
} 
當我試圖從郵遞員發送請求

你請告訴我如何解決這個問題。或者,如果我錯了,你能否建議我正確的方式。 enter image description here 在此先感謝。

回答

0
@RequestMapping(method = RequestMethod.POST, headers = ("content-type=multipart/*"), produces = "application/json", consumes = "image/*") 
public RestResponse save(@RequestParam("bankAddress") String bankAddress, @RequestParam("bankNameAr") String bankNameAr, @RequestParam("bankNameEn") String bankNameEn, @RequestParam("bankPhone") String bankPhone, @RequestParam("bankStatus") BigDecimal bankStatus, @RequestParam("countryId") long countryId, 
     @RequestParam("bankImage") MultipartFile file) { 

. 
. 
. 
} 

並使用byte[] data = file.getBytes();將文件獲取到byte []中並用於進一步處理。

相關問題