@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
相关推荐
risc1234561 分钟前
【备忘录】java.lang.Throwable#addSuppressed这个是干嘛的?栈低来信1 分钟前
Linux侵入式链表详解__万波__2 分钟前
二十三种设计模式(十)--外观模式Geoking.3 分钟前
深度理解 Java 中的 switch —— 从基础到进阶的完整指南赵庆明老师4 分钟前
NET 中深度拷贝一个对象今天你TLE了吗4 分钟前
Java:基于注解实现去重表消息防止重复消费没有bug.的程序员5 分钟前
大规模微服务下的 JVM 调优实战指南北友舰长5 分钟前
基于Springboot+vue大型商场应急预案管理系统的设计与实现【Java毕业设计·安装调试·代码讲解·文档报告】赵庆明老师6 分钟前
在ASP.NET Core Web Api中添加身份验证和授权菜鸟小九6 分钟前
redis基础(java客户端)