@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
相关推荐
じòぴé南冸じょうげん4 分钟前
若依框架favicon.ico缓存更新问题解决方案:本地生效但线上未更新RoboWizard5 分钟前
高性能电脑热战寒冬 11月DIY配置推荐狮子座的男孩8 分钟前
js基础高级:01、数据类型(typeof、instanceof、===的使用)、数据与变量与内存(定义、赋值与内存关系、引用变量赋值、js调函数传参)星释3 小时前
Rust 练习册 57:阿特巴什密码与字符映射技术Cyclo-3 小时前
PDFJS 在React中的引入 使用组件打开文件流PDFzl9798994 小时前
RabbitMQ-下载安装与Web页面向着光芒的女孩5 小时前
【IDEA】关不了的Proxy Authentication弹框探索过程Filotimo_5 小时前
Spring Boot 整合 JdbcTemplate(持久层)kitty_hi5 小时前
mysql主从配置升级,从mysql5.7升级到mysql8.4李慕婉学姐5 小时前
【开题答辩过程】以《“饭否”食材搭配指南小程序的设计与实现》为例,不知道这个选题怎么做的,不知道这个选题怎么开题答辩的可以进来看看