pom.xml
<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.20</version> </dependency> <!--poi实现导入导出功能--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency>
/** * 导出接口 */ @GetMapping("/export") public void export(HttpServletResponse response) throws Exception { // 从数据库查询出所有的数据 List<User> list = userService.list(); // 通过工具类创建writer 写出到磁盘路径 // ExcelWriter writer = ExcelUtil.getWriter(filesUploadPath + "/用户信息.xlsx"); // 在内存操作,写出到浏览器 ExcelWriter writer = ExcelUtil.getWriter(true); //自定义标题别名 writer.addHeaderAlias("username", "用户名"); writer.addHeaderAlias("password"