@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
相关推荐
28岁青春痘老男孩28 分钟前
JDK8+SpringBoot2.x 升级 JDK 17 + Spring Boot 3.x方璧33 分钟前
限流的算法元Y亨H41 分钟前
Nacos - 服务注册Hi_kenyon1 小时前
VUE3套用组件库快速开发(以Element Plus为例)二起名时在学Aiifox1 小时前
Vue 3 响应式缓存策略:从页面状态追踪到智能数据管理曲莫终1 小时前
Java VarHandle全面详解:从入门到精通一心赚狗粮的宇叔1 小时前
中级软件开发工程师2025年度总结正在学习前端的---小方同学1 小时前
Harbor部署教程奋进的芋圆1 小时前
DataSyncManager 详解与 Spring Boot 迁移指南计算机程序设计小李同学2 小时前
个人数据管理系统