@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
相关推荐
hhwyqwqhhwy10 小时前
linux 驱动开发相关IT逆夜11 小时前
实现Yum本地仓库自动同步的完整方案(CentOS 7)李游Leo11 小时前
前端安全攻防指南:XSS / CSRF / 点击劫持与常见防护实践(含真实案例拆解)毕设源码-邱学长11 小时前
【开题答辩全过程】以 基于Java企业人事工资管理系统为例,包含答辩的问题和答案转转技术团队11 小时前
回收系统架构演进实战:与Cursor结对扫清系统混沌AI分享猿11 小时前
Java后端实战:SpringBoot接口遇异常请求,轻量WAF兼顾安全与性能S***267511 小时前
linux上redis升级稚辉君.MCA_P8_Java11 小时前
Gemini永久会员 Java中的四边形不等式优化我命由我1234511 小时前
微信开发者工具 - 模拟器分离窗口与关闭分离窗口E***q53911 小时前
Vue增强现实开发