@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
相关推荐
小王师傅661 分钟前
【Java结构化梳理】泛型-初步了解-下pengyi8710154 分钟前
共享 IP 池多人使用 分层权限与配额管理方案一叶飘零晋5 分钟前
【(一)Electron 使用之如何用vite+vue3搭建初始框架】计算机安禾7 分钟前
【Linux从入门到精通】第33篇:数据库MySQL/MariaDB安装与基础调优逝水如流年轻往返染尘9 分钟前
JAVA中的String类一只叫煤球的猫11 分钟前
ThreadForge 1.2.0 发布:让 Java 并发代码更好写,这次补齐了高阶编排、示例与观测能力光影少年16 分钟前
前端SSR和ssg区别counting money17 分钟前
Spring框架基础(依赖注入-半注解形式)CN-Dust18 分钟前
【C++】for循环例题专题广州华水科技21 分钟前
北斗形变监测传感器在水库安全监测中的应用与发展