首页>代码>springboot2+mybatis+EasyExcel实现从mysql数据库在线导出excel文件>/springboot2.x_ssm/src/main/java/com/springboot/ssm/controller/UserController.java
package com.springboot.ssm.controller; import com.springboot.ssm.domain.User; import com.springboot.ssm.service.UserService; import com.springboot.ssm.util.ExcelUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletResponse; import java.util.List; @Slf4j @Controller @RequestMapping("/user") public class UserController { @Autowired private UserService userService; @RequestMapping("/toUserListPage") public String toUserListPage(ModelMap modelMap) { List<User> userList = userService.getAll(); modelMap.put("userList", userList); return "user/userList"; } @RequestMapping("/getAll") @ResponseBody public List<User> getAll() { return userService.getAll(); } // easyexcel导出Excel到web @GetMapping("/export2Web") public void export2Web(HttpServletResponse response) { try { ExcelUtils.export2Web(response, "最代码用户列表", "最代码用户", User.class, userService.getAll()); } catch (Exception e) { log.error("报表导出异常:", e); } } }