[英]Unsupported Media Type - Spring Boot Rest Controller has consumes/produces JSON and XML but only accepts Json
[英]Spring Boot, download CSV File, Swagger Produces Media Type
您可以直接輸入字符串,而無需使用 MediaType。 例如: produces = "text/csv"
。 text/plain
應該工作得很好,因為 csv 文件只是逗號分隔的文本。
當您從 API 將文件作為字節數組 (ResponseEntity<byte[]>) 返回時,也可以使用八位字節流。此外,正如@Orfeas 提到的,您不必使用 MediaType 中的值。 也不需要生產,因此您不必指定它。 在這種情況下,生成的 swagger 將如下所示:
responses:
200:
description: "Data was successfully sent"
schema:
type: "array"
items:
type: "string"
format: "byte"
在用戶界面方面,如果您使用 javascript fe 或任何 javascript 框架,您可以使用 Blob 類型來處理來自服務器的響應。
也許有更好的解決方案,但我通常使用這個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.