还有比这更好的解决方案吗(OpenApi 使用 JSON 发送 MultipartFile 请求,不支持 get 'application / octet-stream' 错误)?
@PostMapping(path = "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "XX", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Das zu erstellende Ticket", content = @Content(schema = @Schema(implementation = TicketDTO.class))))
TicketDTO createTicket(@RequestPart() @Parameter(required = true) TicketDTO ticket,
@Parameter(description = "Files to be uploaded", content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE)) @RequestPart(value = "files", required = false) MultipartFile[] files)
throws MessagingException;
这对我不起作用。我在 Swagger UI 中没有看到上传文件的选项。
@Operation中不需要设置requestBody。
示例
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Operation(summary = "XX")
public TicketDTO createTicket(@RequestPart() @Parameter(required = true) TicketDTO ticket,
@Parameter(description = "Files to be uploaded", content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE)) @RequestPart(value = "files", required = false) MultipartFile[] files) {
return ticket;
}