@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
相关推荐
小李独爱秋7 分钟前
模拟面试:说一下数据库主从不同步的原因。白云偷星子17 分钟前
RHCSA笔记7tryCbest27 分钟前
Linux常用命令V2026沙白猿1 小时前
【TJXT】Day3百锦再1 小时前
Java的TCP和UDP实现详解毕设源码-朱学姐1 小时前
【开题答辩全过程】以 高校实验室管理系统为例,包含答辩的问题和答案A_B_C_Q1 小时前
StringBuilder 与 StringBuffer的区别用户908324602731 小时前
Spring AI 1.1.2 集成 MCP(Model Context Protocol)实战:以 Tavily 搜索为例洋洋技术笔记1 小时前
vue3+vite+elementplus简单介绍Joker Zxc1 小时前
【前端基础(Javascript部分)】2、JavaScript的变量和数据类型