@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
相关推荐
shoubepatien7 小时前
JAVA -- 12Mr.朱鹏7 小时前
大模型入门学习路径(Java开发者版)上古月฿7 小时前
大学生素质测评系统设计与实现一雨方知深秋7 小时前
程序流程控制FF-Studio7 小时前
Ubuntu 24.04 磁盘爆满“灵异“事件:Btrfs, Snapper 与删不掉的空间码农秋7 小时前
Element Plus DatePicker 日期少一天问题:时区解析陷阱与解决方案爱尔兰极光7 小时前
计算机网络--网络层cike_y7 小时前
JSP标签&JSTL标签&EL表达式未来之窗软件服务7 小时前
未来之窗昭和仙君(五十六)页面_预览模式——东方仙盟筑基期秃然想通7 小时前
Java继承详解:从零开始理解“父子关系”编程