@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 分钟前
Linux —— 进程概念 - 程序地址空间buhuizhiyuci6 分钟前
linux篇-应用商店:“yum / apt“ 的详解哀木6 分钟前
手搓你的 AI 外置记忆,连接飞书体验直接脚踢龙虾董董灿是个攻城狮7 分钟前
荣耀一个做手机的,凭啥机器人夺冠?lifallen10 分钟前
Flink Watermark 设计分析CDN36018 分钟前
【前端进阶】告别“慢”与“不安全”:我是如何用360CDN搞定API加速和HTTPS的Rabbit码工19 分钟前
HTML5 与 CSS3 新特性全解析:从结构优化到视觉升级王美丽1.8519 分钟前
css3选择器噜噜薯20 分钟前
HTML5和CSS3的核心新增特性及其语法.Cnn23 分钟前
Ajax与Vue 生命周期核心笔记