@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
相关推荐
Sylvia-girl7 分钟前
IO流~~weixin1997010801610 分钟前
【性能提升300%】仿1688首页的Webpack优化全记录HypoxiaDream15 分钟前
LINUX-Ext系列⽂件系统小毛驴85016 分钟前
Linux curl 命令用法冰暮流星19 分钟前
javascript之数组李斯啦果22 分钟前
【Linux】Linux目录配置Re.不晚23 分钟前
JAVA进阶之路——无奖问答挑战3AI+程序员在路上23 分钟前
linux下线程中pthread_detach与pthread_join区别代码游侠24 分钟前
C语言核心概念复习——C语言基础阶段logocode_li25 分钟前
说透 Linux Shell:命令与语法的底层执行逻辑