@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
相关推荐
李伟_Li慢慢25 分钟前
01-threejs架构原理-课程简介玖玥拾1 小时前
C# 语言进阶(十五)C# 游戏服务端 MySQL 数据库土星云SaturnCloud1 小时前
边缘计算驱动绿氢生产过程智能寻优:电解槽级实时优化技术解析Darkwanderor1 小时前
对Linux的进程控制的研究我命由我123452 小时前
执行 Gradle 指令报错,无法将“grep”项识别为 cmdlet、函数、脚本文件或可运行程序的名称考虑考虑2 小时前
Sentinel安装_瑞2 小时前
深入理解 iOS 渲染原理IT_陈寒2 小时前
SpringBoot自动配置失灵?你可能忘了这个关键注解iCOD3R2 小时前
Skill - kill-ai-slop 解决“AI 味”样式Web极客码2 小时前
突破并发瓶颈:云端高性能架构如何赋能海外 AI Agent 矩阵的高效产出