@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 小时前
Spring Bean 生命周期Wang's Blog4 小时前
Java 项目实战: 交友项目:登录链路回顾与今日任务地图Chenyu_3104 小时前
DPDK、TC 和 XDP:Linux 高性能网络到底在优化什么信誓旦旦的程序猿5 小时前
【Python量化实战宝典 #08】可转债与债券接口手册:转股价·溢价率·纯债价值(Python 可跑)砚底藏山河5 小时前
python量化:行情数据回溯Jlzn88885 小时前
华东电芯分选通道数怎么配才不堵线香吧香5 小时前
GRPC连接机制---长连接分析我是人✓6 小时前
SpringBoot项目的五种创建方式原则猫6 小时前
UDP 到底怎么实现可靠的Java后端的Ai之路6 小时前
14、ReactJS - 路由(Router)