@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
相关推荐
androidstarjack3 分钟前
2026 年 IM 即时通讯方案选型实践:4 家主流厂商对比分析object not found4 分钟前
UniCloud 本地调试云对象报 Cannot find module ‘uni-id-common‘ 的排查与解决跨境小技8 分钟前
2026 Shopee数据抓取逐步教程:技术难点、解决思路与实战方法2301_815357709 分钟前
SpringBoot两大核心数据库连接池:HikariCP与Druid深度实践一枚小太阳11 分钟前
想学 Electron?这份「能跑的示例集」一篇搞懂是Dream呀11 分钟前
自动化打造信息影响力:用 Web Unlocker 和 n8n 打造你的自动化资讯系统JinchuanMaster12 分钟前
Ubuntu20.04安装50系显卡驱动[不黑屏版本]草莓熊Lotso14 分钟前
Linux 程序地址空间深度解析:虚拟地址背后的真相郝学胜-神的一滴16 分钟前
使用Linux命名管道(FIFO)实现无血缘关系进程间通信Jinkxs16 分钟前
【Linux】零基础入门:一篇吃透操作系统核心概念