@ApiOperation(value = "模板下载")
@PostMapping("/download")
public void download(HttpServletResponse res) {
String filePath = "./template/基础数据模板.xlsx"; //模板文件存放路径
try (OutputStream os = res.getOutputStream();
InputStream bis = new BufferedInputStream(new ClassPathResource(filePath).getStream())) {
String type = new MimetypesFileTypeMap().getContentType("基础数据模板.xlsx");
res.setContentType(type);
String name = URLEncoder.encode("goods.xlsx", "UTF-8");
res.setHeader("Content-Disposition", "attachment;filename=" + name);
download(os, bis); //业务层方法
} catch (Exception e) {
e.printStackTrace();
}
}
public void download(OutputStream outputStream, InputStream inputStream) {
try {
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
workbook.write(outputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
08-31
2167

06-13
165

10-21
07-29
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交