5分钟下载excel模板

复制代码
@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());
    }
相关推荐
buhuimaren_几秒前
GFS分布式文件系统
linux
踩着两条虫2 分钟前
VTJ:核心引擎
前端·低代码·ai编程
程序员老邢4 分钟前
【技术底稿 18】FTP 文件处理 + LibreOffice Word 转 PDF 在线预览 + 集群乱码终极排查全记录
java·经验分享·后端·pdf·word·springboot
被摘下的星星13 分钟前
网络设备有哪些
服务器·网络
aini_lovee15 分钟前
基于C#的三菱PLC串口通信实现方案
服务器·网络·c#
不做无法实现的梦~15 分钟前
显示屏和显卡驱动问题完整解决教程---ubuntu22.04安装显卡驱动解决显示屏黑屏幕问题
linux·学习
.柒宇.16 分钟前
共享文件服务NFS服务器:NFS实战详解
linux·运维·服务器
磊 子22 分钟前
类模板与派生1
java·开发语言·c++
GISer_Jing24 分钟前
AI时代前端开发者成长计划
前端·人工智能
一叶之秋141225 分钟前
通信之道:解锁Linux进程间通信的无限可能(三)
linux·运维·服务器