@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
相关推荐
Warson_L21 小时前
上传头像 (angular 16)zhanlang021721 小时前
HTML 零基础入门到企业实战【第七章 表单标签|7.1 表单核心作用:数据收集、用户交互原理】Java后端的Ai之路21 小时前
Java并发编程22-Lock接口FungLeo21 小时前
成为全栈·Vue 管理后台篇·Biome、类型检查、构建和API 代理如何组成质量门禁文丑颜不良啊21 小时前
LeetCode3081~3100题目解析夕水21 小时前
受不了满屏广告的诗词网站,以及很多打不开的诗词网站,我干脆自己租服务器用trae重构了一个(纯公益、无广告)SimonKing21 小时前
快讯!local-notes素笺笔记又又又更新了!Rain的Java大神之路1 天前
面试官:设计一个自动售货机系统。我:别急着写代码,先问5个问题|状态机+防超卖+断电自愈,一套答法讲透挖掘狂人1 天前
飞书群聊已读,是怎么实现的?星恒随风1 天前
MySQL 从零入门(七):索引原理与 B+ 树详解——从磁盘 I/O 到 InnoDB 聚簇索引