@PostMapping("/downloadTemplate")
@Operation(summary="下载入职excel模板")
public void downloadExcel(HttpServletResponse response){
try{
//获取输入流,原始模板位置
String filePath = "template/gridPersonTemplate.xlsx";
ClassPathResource resource = new ClassPathResource(filePath);
InputStream bis = resource.getInputStream();
//假如以中文名下载的话,设置下载文件名称
String filename = "gridPersonTemplate1.xlsx";
//转码,免得文件名中文乱码
filename = URLEncoder.encode(filename,"UTF-8");
//设置文件下载头
response.addHeader("Content-Disposition", "attachment;filename=" + filename);
//1.设置文件ContentType类型,这样设置,会自动判断下载文件类型
response.setContentType("multipart/form-data");
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
int len = 0;
while((len = bis.read()) != -1){
out.write(len);
out.flush();
}
out.close();
}catch (Exception e){
log.error(e.getMessage());
}
5分钟下载excel模板
被程序耽误的胡先生2025-02-22 8:25
相关推荐
程序员黑豆2 小时前
Java 注释详解:单行、多行与文档注释的完整指南剪刀石头布啊2 小时前
antd中可编辑表格中巧用useWatch实现联动高性能效果,以及定制延伸学习油丶酸萝卜别吃2 小时前
前端转全栈学习路线浮生望3 小时前
前端路由进阶:History API原理与手写HistoryRouterhey_sml3 小时前
JAVA每日一学---CompletableFuture中thenApply与thenCompose区别详解Doraemomo3 小时前
数据结构-环形链表数智工坊3 小时前
Zotero自建Ubuntu WebDAV附件同步方案(完美解决存储空间不足)陆枫Larry3 小时前
JavaScript 中的竞态是什么,为啥会有竟态?江畔柳前堤4 小时前
HBM:大语言模型时代的「算力血液」——从内存墙到带宽革命的深度拆解萧瑟余晖4 小时前
Java深入解析篇十七之SpringCloud