1.前端
window.location.href = "/system/dept/download2?excel_path=" + result.dept_excel_path;
2.后端
@GetMapping("/download2")
@ApiOperation(value = "下载错误数据Excel", notes = "下载错误数据Excel", httpMethod = "POST")
public AjaxResult download(String excel_path, HttpServletResponse response, HttpServletRequest request) {
try {
String filePath = excel_path;
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + setFileDownloadHeader(request, "单位目录错误数据.xlsx"));
FileUtils.writeBytes(filePath, response.getOutputStream());
FileUtils.deleteFile(filePath);
} catch (Exception e) {
logger.error("下载文件失败", e);
}
return success().put("dept_excel_path", excel_path);
}