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());
    }
相关推荐
我不吃饼干32 分钟前
在 React 中实现倒计时功能会有什么坑
前端·react.js
心一信息35 分钟前
如何在Ubuntu上部署excalidraw
linux·运维·ubuntu
小小小小宇1 小时前
前端PerformanceObserver
前端
人生匆匆1 小时前
linux ext4缩容home,扩容根目录
linux·运维·服务器
王者鳜錸1 小时前
PYTHON从入门到实践-18Django从零开始构建Web应用
前端·python·sqlite
拾光拾趣录1 小时前
ES6到HTTPS全链路连环拷问,99%人第3题就翻车?
前端·面试
Linux技术芯1 小时前
#Linux内存管理#缺页中断处理的核心函数是do_page_fault()的工作原理
linux
超级晒盐人2 小时前
用落霞归雁的思维框架推导少林寺用什么数据库?
java·python·系统架构·学习方法·教育电商
yuanzhengme2 小时前
Shell【脚本 02】离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)
linux·zookeeper·kafka·自动化·安装脚本
岁忧2 小时前
(LeetCode 面试经典 150 题) 138. 随机链表的复制 (哈希表)
java·c++·leetcode·链表·面试·go