@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
相关推荐
Csvn10 分钟前
容器查询 @container 实战:告别无休止的媒体查询一叶龙洲1 小时前
win11与Ubuntu之间同步配置、插件CHANG_THE_WORLD2 小时前
12.总结:深入理解 Linux I/O 多路复用:select、poll、epoll 全解析风曦Kisaki2 小时前
# Linux笔记:操作系统优化与资源管理稚南城才子,乌衣巷风流2 小时前
函数:编程中的核心概念Mr.HeBoYan3 小时前
一次持续三天才出现的丢包故障——深入解析 DPDK Memory Ordering、rte_ring 与 CPU Memory Barrier (下)大模型码小白3 小时前
JAVA 集合框架进阶:List 与 Set 的深度解析与实战IT_陈寒3 小时前
为什么我的JavaScript异步代码总是不按顺序执行?索西引擎4 小时前
【React】useState 状态更新机制:批量更新策略与“异步“错觉的深层解析名字还没想好☜4 小时前
Go 的 time.Ticker 陷阱:定时任务里被忽略的内存泄漏与正确关闭