@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
相关推荐
wanhengidc2 小时前
云计算时代 云手机与云服务器的不同后端小张2 小时前
【JAVA进阶】Spring Boot 核心知识点之自动配置:原理与实战veneno7 小时前
大量异步并发请求控制并发解决方案tg-zm8899967 小时前
2025返利商城源码/挂机自动收益可二开多语言/自定义返利比例/三级分销理财商城X***C8627 小时前
SpringBoot:几种常用的接口日期格式化方法阿巴~阿巴~7 小时前
JsonCpp:C++ JSON处理利器j***29487 小时前
IPV6公网暴露下的OPENWRT防火墙安全设置(只允许访问局域网中指定服务器指定端口其余拒绝)i***t9197 小时前
Spring Boot项目接收前端参数的11种方式ao_lang7 小时前
数据链路层前端达人7 小时前
你的App消息推送为什么石沉大海?看Service Worker源码我终于懂了