【发布时间】:2019-12-18 14:46:57
【问题描述】:
我们能否在 Rest Service 中同时提供 Json 响应和 csv 文件作为附件?
我已经编写了如下代码,但我也确信它不会工作。
ResponseBuilder responseBuilder = null;
responseBuilder = Response.status(200).type(MediaType.APPLICATION_JSON)
.entity(parseOrganizations(getOrganizationsResponseMashery(limit, offset)));
responseBuilder.type(MediaType.TEXT_PLAIN).entity(file).header("Content-Disposition", "attachment; filename=Organizations.csv");
return responseBuilder.build();
带有文件的实体的第二个设置器,基本上覆盖了我之前作为实体插入的 json 内容。所以请建议。
【问题讨论】:
-
我认为下面的solution 是你要找的。span>
标签: java rest spring-boot response spring-jersey