@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
相关推荐
超哥--9 小时前
B站视频内容智能分析系统(九):React 前端与管理面板devilnumber10 小时前
Java 递归算法 详解 + 核心要点 + 实战运用 + 避坑指南kebidaixu11 小时前
BCU 平台 RS485 驱动适配:从 THVD1406 到 ISO3082asdfg125896312 小时前
JavaBean是什么?怎么理解?有什么用途?Cutecat_12 小时前
视频字幕处理工具横向:提取模式 vs 编辑模式,该如何选择qq_4221525713 小时前
PDF 加水印工具怎么选?2026 年文档版权保护方案对比kyriewen13 小时前
手写 Promise.all、race、any:不到 30 行代码,解决并发异步的所有姿势映翰通朱工13 小时前
工业4G网关无公网IP远程运维实战(内网终端异地访问方案)洪晓露13 小时前
将 rke2 集群证书延长至 10 年谢平康13 小时前
解决用 rm 报bash: /usr/bin/rm: Argument list too long错