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());
    }
相关推荐
fie88892 分钟前
LabVIEW与串口服务器TCP通信测试程序
服务器·tcp/ip·labview
weixin_704266054 分钟前
Spring Boot 入门了解
前端·firefox
残雪飞扬5 分钟前
Ubuntu上安装 WinBoat(让linux上运行windows软件)
linux·windows·ubuntu
m0_683124796 分钟前
无U盘装Ubuntu
linux·运维·ubuntu
星如雨グッ!(๑•̀ㅂ•́)و✧7 分钟前
Webflux onErrorStop使用
java
java1234_小锋7 分钟前
Java高频面试题:RocketMQ有哪些使用场景?
java·zookeeper·java-zookeeper
默|笙8 分钟前
【Linux】进程信号(2)_信号捕捉_中断
linux·运维·服务器
冲浪中台8 分钟前
如何实现低代码源码级交付和私有化部署
前端·低代码·私有化部署·源代码管理
wellc10 分钟前
SpringCloud系列教程:微服务的未来(十四)网关登录校验、自定义过滤器GlobalFilter、GatawayFilter
java·spring cloud·微服务
图灵机z13 分钟前
【操作系统】四、进程管理
linux·服务器·网络·windows·macos·centos·risc-v