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());
    }
相关推荐
瀚高PG实验室8 小时前
数据库安全配置指导
服务器·数据库·瀚高数据库
charlie1145141918 小时前
从零开始理解 CSS:让网页“活”起来的语言2
前端·css·笔记·学习·选择器·样式表·原生
new_daimond8 小时前
Linux 服务器内存监控与优化指南
linux·服务器·chrome
一介草民丶8 小时前
Linux | Mongodb 6 离线安装
linux·运维·mongodb
赖small强8 小时前
Linux 线程相关结构对照表与关系图
linux·thread_info·task_struct·thread_struct
Justin_198 小时前
部署zabbix
linux·centos·zabbix
浪裡遊8 小时前
Next.js路由系统
开发语言·前端·javascript·react.js·node.js·js
mapbar_front8 小时前
职场中的顶级能力—服务意识
前端
Deamon Tree8 小时前
【设计题】如何实现限流器
java
STUPID MAN8 小时前
Linux使用tomcat发布vue打包的dist或html
linux·vue.js·tomcat·html