@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
相关推荐
帮帮志4 分钟前
vue实现与后台springboot传递数据【传值/取值 Axios 】Willis_m5 分钟前
Linux 服务器用 SSH 拉取多个 Git 工程紫金修道12 分钟前
【Linux】在Arm服务器源码编译onnxruntime-gpu的whlxixingzhe218 分钟前
Nginx 配置多个监听端口Clockwiseee26 分钟前
文件上传总结liyi_hz200829 分钟前
O2OA(翱途)开发平台系统安全-用户登录IP限制purrrew31 分钟前
【Java ee初阶】初始网络程序员Bears35 分钟前
从零打造个人博客静态页面与TodoList应用:前端开发实战指南Helibo441 小时前
GESPC++六级复习清风细雨_林木木1 小时前
Vue 2 项目中配置 Tailwind CSS 和 Font Awesome 的最佳实践