【发布时间】:2018-04-05 19:02:09
【问题描述】:
我有这样的休息服务:
import org.apache.tomcat.util.http.fileupload.IOUtils;
@RequestMapping(value = "/xxx", method = GET)
public void getExcel(HttpServletResponse resp) {
resp.setHeader("Content-Disposition", "attachment; filename=\"NAME.xlsx\"");
resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
try (ServletOutputStream outputStream = resp.getOutputStream()) {
IOUtils.copy(A-VALID-FILE-INPUT-STREAM, outputStream);
resp.flushBuffer();
} catch (IOException e) {
throw new AppException(e);
}
}
问题是每次我调用此服务时默认保存名称都是'response',我尝试返回HttpEntity<byte[]>,创建像HttpHeaders() 这样的对象,但没有任何变化。
感谢任何帮助
【问题讨论】:
-
你是在邮递员那里做的吗?邮递员总是要求保存带有名称响应的文档。
-
好像是想调用服务来下载文件,有没有参考这篇帖子-download a file from Spring boot rest service?
-
对,我用的是邮递员,哦,是因为这个吗?
标签: spring-boot java-8 apache-poi content-disposition