簡體   English   中英

使用Spring Boot使用自定義DTO進行多部分請求

[英]Multipart Request with Custom DTO using Spring Boot

下面是我的Rest API,它接受多部分文件和自定義dto

@RequestMapping(path="/manual", method = RequestMethod.POST) 
public ResponseEntity<?> createObject(@RequestPart CustomDTO dto, @RequestPart(name = "file", required = true) MultipartFile file) { 

    //Some code here

}

以下是CustomDTO

public class CustomDTO implements Serializable { 

// Few attributes and its respective getters and setter are there

}

現在在發出請求時,它給我一個錯誤,如下所示 在此處輸入圖片說明

但是,如果我將數據類型設置為String,則使用rest api而不是CustomDTO ,則它可以正常工作,然后使用objectmapper可以將其轉換為CustomDTO 但是,請幫助我了解如何直接將其作為CustomDTO而不是String接受。

注意:我正在使用Spring Boot

嘗試以下一項。

@RequestMapping(value = "/manual", method = RequestMethod.POST)
public ResponseEntity<?> createObject( @Valid CustomDTO dto, @RequestParam("file") MultipartFile file ) {
        //
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM