临时笔记,用于手机电脑端传输

@GetMapping("/doExport")
    public void doExport(HttpServletRequest request, HttpServletResponse response) throws IOException {

        List list = userMapper.selectList(null);

        //在内存操作,写到浏览器
        ExcelWriter writer = ExcelUtil.getWriter(true);

        //自定义标题别名(将对应的字段转化成自己需要的名称)
        writer.addHeaderAlias("id", "组织编号");
        writer.addHeaderAlias("userName", "组织名称");
        writer.addHeaderAlias("passWord", "组织类型");
        writer.addHeaderAlias("realName", "定位类型");
        writer.addHeaderAlias("time", "组织层级");

        writer.setOnlyAlias(true);
        //默认配置
        writer.write(list, true);
        //设置content—type
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");

        //设置标题
        String fileName = URLEncoder.encode("组织信息", "UTF-8");
        //Content-disposition是MIME协议的扩展,MIME协议指示MIME用户代理如何显示附加的文件。
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        ServletOutputStream outputStream = response.getOutputStream();

        //将Writer刷新到OutPut
        writer.flush(outputStream, true);
        outputStream.close();
        writer.close();
    }

https://blog.csdn.net/javajy/article/details/129470823

尚硅谷前端全套视频教程
B站直达免费在线看:https://space.bilibili.com/302417610/channel/seriesdetail?sid=457615
免费视频及资料下载地址:https://pan.baidu.com/s/1BM_OKMXXAGxMNqaBN_7tRg ,提取码:afyt

学习路线及下载导航:http://www.atguigu.com/html5_video.shtml#html
围观尚硅谷前端课程:http://www.atguigu.com/web

尚硅谷Java全套视频教程
B站直达免费在线看:https://space.bilibili.com/302417610/channel/seriesdetail?sid=457613
免费视频及资料下载地址:https://pan.baidu.com/s/1YWQ7aGX45Wvazw5ZUybglQ?pwd=yyds 提取码:yyds 

学习路线及下载导航:http://www.atguigu.com/download.shtml
围观尚硅谷Java课程:http://www.atguigu.com/java

姜泳 你好,欢迎加入领课教育系统开源项目讨论群。
提问前请先看完文档:https://eduos.roncoo.net/doc/faq/
SQL脚本和Nacos配置获取:https://www.roncoo.net/open

你可能感兴趣的:(Java进阶学习,servlet,java,服务器)