@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
相关推荐
nanxun88627 分钟前
记一次诡异的 Docker 容器"串包"故障排查Pedantic34 分钟前
SwiftUI 手势笔记橙子家1 小时前
浏览器缓存之【结构化数据库与缓存】: IndexedDB、Cache storage 和 Storage bucketsuser20585561518131 小时前
X6 中边悬浮置顶,规避 `mouseleave` 事件丢失问题李明卫杭州1 小时前
CSS aspect-ratio 属性完全指南用户1563068103513 小时前
Day01 | Java 基础(Java SE)Pedantic3 小时前
SwiftUI 手势层级(Gesture Hierarchy)详解飘尘3 小时前
前端转型全栈(Java后端)的快速上手指引一颗烂土豆4 小时前
Meshopt 压缩深度解析,为什么它比 Draco 更快