//下载模板
@RequestMapping("/download")
public void download(HttpServletResponse response) {
logger.info("开始下载模板--------------->");
//获取要下载的模板名称
String fileName = "footMark.xlsx";
//设置要下载的文件的名称
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
//通知客服文件的MIME类型
response.setContentType("application/vnd.ms-template;charset=UTF-8");
//获取resource下的templates文件夹下的文件的路径
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("templates/"+fileName)) {
//读取excel模板
XSSFWorkbook wb = new XSSFWorkbook(inputStream);
OutputStream os = new BufferedOutputStream(response.getOutputStream());
wb.write(os);
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}