@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 分钟前
鸿蒙5开发宝藏案例分享---切面编程实战揭秘Java知识库7 分钟前
「深度拆解」Spring Boot如何用DeepSeek重构MCP通信层?从线程模型到分布式推理的架构进化愚润求学8 分钟前
【Linux】POSIX信号量喵手9 分钟前
CSS3 渐变、阴影和遮罩的使用顽强d石头11 分钟前
bug:undefined is not iterable (cannot read property Symbol(Symbol.iterator))烛阴20 分钟前
模块/命名空间/全局类型如何共存?TS声明空间终极生存指南进阶的DW20 分钟前
新手小白使用VMware创建虚拟机安装Linux火车叼位24 分钟前
Git 精准移植代码:cherry-pick 简单说明oioihoii24 分钟前
C++11 尾随返回类型:从入门到精通jz_ddk25 分钟前
[zynq] Zynq Linux 环境下 AXI BRAM 控制器驱动方法详解(代码示例)