@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
相关推荐
芝士雪豹只抽瑞克五12 小时前
Nginx 高性能Web服务器笔记精神状态良好13 小时前
实战:从零构建本地 Code Review 插件荒诞英雄13 小时前
Vue3 Teleport我真是没招了YAY_tyy13 小时前
2025 最新版 Node.js 下载安装及环境配置教程百思可瑞教育13 小时前
Vue 前端与 Node.js 后端文件上传与处理实现玹外之音13 小时前
Spring AI MCP 无状态服务器实战:构建AI智能用户管理系统java干货13 小时前
Redis 的 ZipList 是什么?它是怎么解决内存碎片问题的?架构师汤师爷13 小时前
一文彻底搞懂 OpenClaw 的架构设计与运行原理(万字图文)苑若轻航13 小时前
防抖和节流:解决高频事件性能失重外太空啦13 小时前
Tomcat