@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
相关推荐
喝拿铁写前端2 小时前
别再让 AI 直接写页面了:一种更稳的中后台开发方式五岳3 小时前
分库分表数据源ShardingSphereDataSource的Connection元数据误用问题分析带刺的坐椅3 小时前
迈向 MCP 集群化:Solon AI (支持 Java8+)在解决 MCP 服务可扩展性上的探索与实践G_H_S_3_3 小时前
【网络运维】Docker 存储:镜像层与数据卷的管理应用鼠爷ねずみ4 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中A向前奔跑4 小时前
前端实现实现视频播放的方案和面试问题代码or搬砖4 小时前
String字符串十一.3664 小时前
131-133 定时器的应用xhxxx4 小时前
你的 AI 为什么总答非所问?缺的不是智商,是“记忆系统”