@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
相关推荐
llwszx1 小时前
深入理解Java锁原理(一):偏向锁的设计原理与性能优化云泽野1 小时前
【Java|集合类】list遍历的6种方式二进制person2 小时前
Java SE--方法的使用物联网老王2 小时前
Ubuntu Linux Cursor 安装与使用一耶啵奶膘2 小时前
uniapp+firstUI——上传视频组件fui-upload-video小阳拱白菜3 小时前
java异常学习视频砖家3 小时前
移动端Html5播放器按钮变小的问题解决方法lyj1689973 小时前
vue-i18n+vscode+vue 多语言使用FrankYoou4 小时前
Jenkins 与 GitLab CI/CD 的核心对比一位摩羯座DBA4 小时前
Redhat&Centos挂载镜像