首页>代码>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);
        }
    }
}
最近下载更多
镜影  LV3 2023年9月14日
yunYUN123  LV1 2023年5月19日
微信网友_6145740972576768  LV2 2022年12月21日
菜鸟666  LV2 2022年8月28日
汤汤汤要学编程  LV11 2022年8月21日
June06  LV2 2022年4月25日
test12312321  LV14 2022年2月25日
Ditto123  LV8 2021年12月9日
huaua7676  LV30 2021年11月10日
tansuo阿郎  LV8 2021年11月5日
最近浏览更多
WBelong  LV7 3月28日
冰枫xjz8  LV31 2023年12月11日
爱情戴罪的羔羊  LV7 2023年10月27日
601601lmy  LV5 2023年10月20日
duon12  LV1 2023年9月25日
镜影  LV3 2023年9月14日
Eddie233  LV5 2023年6月14日
yunYUN123  LV1 2023年5月19日
微信网友_6467077197238272  LV1 2023年5月8日
微信网友_6401519212040192  LV1 2023年4月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友