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());
    }
相关推荐
未知原色几秒前
NODE.JSB快速下载及安装
linux·运维·node.js
⑩-2 分钟前
JVM-内存模型
java·jvm
小年糕是糕手3 分钟前
【C++】内存管理(上)
java·开发语言·jvm·c++·算法·spring·servlet
222you4 分钟前
vue目录文件夹的作用
前端·javascript·vue.js
wanhengidc5 分钟前
云手机大规模出现的趋势 巨 椰
运维·服务器·科技·智能手机·云计算
月屯5 分钟前
pandoc安装与使用(html、makdown转docx、pdf)
前端·pdf·html·pandoc·转docx、pdf
kyle~5 分钟前
Linux---scp 安全文件传输
linux·网络·安全
Qiuner5 分钟前
Spring Boot 机制五: Bean 生命周期与后置处理器(BeanPostProcessor)源码深度剖析
java·spring boot·后端
路边草随风6 分钟前
java实现发布flink yarn session模式作业
java·flink·yarn
qq_12498707538 分钟前
基于Spring Boot的阳光餐盘点餐系统(源码+论文+部署+安装)
java·vue.js·spring boot·后端·毕业设计