@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
相关推荐
我不吃饼干32 分钟前
在 React 中实现倒计时功能会有什么坑心一信息35 分钟前
如何在Ubuntu上部署excalidraw小小小小宇1 小时前
前端PerformanceObserver人生匆匆1 小时前
linux ext4缩容home,扩容根目录王者鳜錸1 小时前
PYTHON从入门到实践-18Django从零开始构建Web应用拾光拾趣录1 小时前
ES6到HTTPS全链路连环拷问,99%人第3题就翻车?Linux技术芯1 小时前
#Linux内存管理#缺页中断处理的核心函数是do_page_fault()的工作原理超级晒盐人2 小时前
用落霞归雁的思维框架推导少林寺用什么数据库?yuanzhengme2 小时前
Shell【脚本 02】离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)岁忧2 小时前
(LeetCode 面试经典 150 题) 138. 随机链表的复制 (哈希表)