@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
相关推荐
fie88892 分钟前
LabVIEW与串口服务器TCP通信测试程序weixin_704266054 分钟前
Spring Boot 入门了解残雪飞扬5 分钟前
Ubuntu上安装 WinBoat(让linux上运行windows软件)m0_683124796 分钟前
无U盘装Ubuntu星如雨グッ!(๑•̀ㅂ•́)و✧7 分钟前
Webflux onErrorStop使用java1234_小锋7 分钟前
Java高频面试题:RocketMQ有哪些使用场景?默|笙8 分钟前
【Linux】进程信号(2)_信号捕捉_中断冲浪中台8 分钟前
如何实现低代码源码级交付和私有化部署wellc10 分钟前
SpringCloud系列教程:微服务的未来(十四)网关登录校验、自定义过滤器GlobalFilter、GatawayFilter图灵机z13 分钟前
【操作系统】四、进程管理