@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
相关推荐
码农水水10 分钟前
SpringBoot配置优化:Tomcat+数据库+缓存+日志全场景教程毕设源码-朱学姐10 分钟前
【开题答辩全过程】以 基于ssm的电影推荐与分享平台的设计与实现为例,包含答辩的问题和答案Wpa.wk11 分钟前
Docker- 故障注入(混沌工程)测试(简单过程阐述)江湖有缘11 分钟前
Docker部署NextTrace Web路由工具独自破碎E13 分钟前
LCR004-只出现一次的数字IIElias不吃糖17 分钟前
Spring Bean 注入与容器管理:从“怎么交给容器”到“怎么被注入使用”的完整总结iFlow_AI19 分钟前
将iFlow CLI装进u盘,即插即用Chan1625 分钟前
《Redis设计与实现》| 常用数据类型与AOF、RDB持久化wljt26 分钟前
游标分页原理weixin_4569074134 分钟前
【html+Tss 故障排查】链20230304 最详细解析之像素已拉取,容器仍起不来(含命令清单)