@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 分钟前
React 19 全栈开发实战指南DanCheOo3 分钟前
AI Streaming 架构:从浏览器到服务端的全链路流式设计SPC的存折5 分钟前
1、MySQL故障排查与运维案例Lyyaoo.5 分钟前
【JAVA基础面经】线程的状态Hello小赵6 分钟前
C语言如何自定义链接库——编译与调用Run_Teenage6 分钟前
Linux:认识信号,理解信号的产生和处理我是小趴菜9 分钟前
前端如何让图片、视频、pdf等文件在浏览器直接下载而非预览希望永不加班10 分钟前
SpringBoot 配置绑定:@ConfigurationProperties悟空码字11 分钟前
MySQL性能优化的天花板:10条你必须掌握的顶级SQL分析技巧cg3314 分钟前
开源项目自动化:用 GitHub Actions 让每个 Issue 都被温柔以待