@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
相关推荐
java1234_小锋6 小时前
Java高频面试题:Redis的Key和Value的设计原则有哪些?欲买桂花同载酒5826 小时前
程序人生-Hello’s P2P八月的雨季 最後的冰吻6 小时前
FFmepg-- 38-Jitter Buffer固定值c程序分析iPadiPhone6 小时前
流量洪峰下的数据守护者:InnoDB MVCC 全实现深度解析Nuopiane6 小时前
关于C#/Unity中单例的探讨win x6 小时前
JVM类加载及双亲委派模型Rsun045516 小时前
React相关面试题jyfool6 小时前
Ubuntu 远程桌面配置踩坑实录:从 TightVNC 到 x11vnc 的折腾之旅毕设源码-赖学姐6 小时前
【开题答辩全过程】以 滑雪场租赁管理系统的设计与实现为例,包含答辩的问题和答案Javatutouhouduan6 小时前
SpringBoot整合reids:JSON序列化文件夹操作实录