【发布时间】:2017-04-24 15:27:11
【问题描述】:
对于使用 Spring 下载文件,我使用的是 GET 方法。
@RequestMapping(value = "/exportar/{tipo}", method = RequestMethod.GET)
@ResponseBody
public void exportar(HttpServletResponse response,@PathVariable TipoEnum tipo) throws IOException{
File file = service.exportar(tipo);
response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", file.getName() + ".xls"));
response.setContentType("application/ms-excel; charset=UTF-8");
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
FileCopyUtils.copy(inputStream, response.getOutputStream());
}
如何使用 POST 来实现这一点?这可能吗?
@RequestMapping(value = "/exportar", method = RequestMethod.POST)
【问题讨论】:
-
而且改成POST就不行了?您需要的只是将响应标头设置为文件。你可以在这里找到灵感:stackoverflow.com/questions/16652760/…
-
POST是一种 POST 数据而不是接收数据的方法,所以我认为使用POST下载文件不是一个好主意。 -
同意你@noname
标签: java spring spring-data