在写java 的文件下载的时候一直抛出异常
getOutputStream() has already been called for this response
抛出异常getOutputStream() has already been called for this response
直到使用了下面的方法:
/**
* 稿源周报excel表格下载
* @return
*/
@RequestMapping(value = "/downExcel", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@ResponseBody
public String downExcel(HttpServletResponse response) throws UnsupportedEncodingException {
LocalDate end = LocalDate.now();
LocalDate start = end.minusDays(14);
String filename = "稿源抓取周报-" + end.format(DateTimeFormatter.ISO_DATE) + ".xlsx";
String filepath = "files/" + filename;
writeExcelFile(start, end, filepath);
// 如果文件名不为空,则进行下载
if (filename != null) {
File file = new File(filepath);
// 如果文件存在,则进行下载
if (file.exists()) {