
我想在spring boot控制器中接收多行,尝试了不同的方法,但无法做到。我正在和邮递员测试。
控制器
@PostMapping(URLConstant.URL_SC_ATTACHMENT_POST)
public ResponseEntity<ApiResponse> storeFile(@RequestParam("attachmentDto") List<BudgetSceAttachmentDto> attachmentDto) throws IOException {
System.out.println(attachmentDto);
return ResponseUtil.getResponse(HttpStatus.OK, MsgConstant.BUDGET_MSG_FILE_UPLOADED, null);
}DTO
private Integer versionId;
private String fileName;
private String pathUploadedFile;
private String uploadedFileName;
private MultipartFile file;发布于 2019-09-11 20:27:24
首先,request的content-type应该是multipart/form-data。
然后让我们简化这个问题-选中upload multiple file first。
@PostMapping(URLConstant.URL_SC_ATTACHMENT_POST)
public ResponseEntity<ApiResponse> storeFile(@RequestParam MultipartFile[] files) throws IOException {
Assert.isTrue(files.length == 2, "files length should be 2");
System.out.println(files.length);
return ResponseUtil.getResponse(HttpStatus.OK, MsgConstant.BUDGET_MSG_FILE_UPLOADED, null);
}如果它运行良好,现在是时候再次引入DTO了。
@PostMapping(URLConstant.URL_SC_ATTACHMENT_POST)
public ResponseEntity<ApiResponse> storeFile(@ModelAttribute List<BudgetSceAttachmentDto> params) throws IOException {
Assert.isTrue(params.length == 2, "files length should be 2");
System.out.println(params.length);
return ResponseUtil.getResponse(HttpStatus.OK, MsgConstant.BUDGET_MSG_FILE_UPLOADED, null);
}https://stackoverflow.com/questions/57888302
复制相似问题