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());
    }
相关推荐
翼龙云_cloud几秒前
阿里云渠道商:轻量应用服务器连接常见问题与解决指南
服务器·阿里云·云计算
互联网哪些事情1 分钟前
服务器防御 SQL 注入
运维·服务器·sql·sql注入主机
小张程序人生5 分钟前
《系统掌握 ShardingSphere-JDBC:分库分表、读写分离、分布式事务一网打尽》
java·mysql
小尧嵌入式5 分钟前
QT软件开发知识点流程及记事本开发
服务器·开发语言·数据库·c++·qt
爱宇阳5 分钟前
Linux 安全加固:设置命令行无操作超时退出
linux·运维·安全
呆萌小新@渊洁6 分钟前
声纹模型全流程实践-开发(训练 - 微调 - 部署 - 调用)
linux·服务器·python·语音识别
carry杰9 分钟前
nacos bootstrap.yml 动态配置开发测试线上模式
前端·bootstrap·html
RisunJan10 分钟前
Linux命令-getenforce命令(快速检查 Linux 系统中 SELinux 的当前运行模式)
linux·运维·服务器
SMF191911 分钟前
解决在 Linux 系统中,当你尝试以 root 用户登录时遇到 “Access denied“ 的错误
java·linux·服务器
翼龙云_cloud12 分钟前
亚马逊云渠道商:新手怎么利用AWS Lightsail部署 WordPress?
运维·服务器·云计算·aws