src/main/java/com/xtu/hrms/controller/EmpController.java

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.xtu.hrms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xtu.hrms.bean.Dept;
import com.xtu.hrms.bean.Emp;
import com.xtu.hrms.bean.Nation;
import com.xtu.hrms.bean.Position;
import com.xtu.hrms.config.PaginationConstant;
import com.xtu.hrms.service.IDeptService;
import com.xtu.hrms.service.IEmpService;
import com.xtu.hrms.service.INationService;
import com.xtu.hrms.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class EmpController {
    @Autowired
    IEmpService empService;

    @Autowired
    IDeptService deptService;

    @Autowired
    INationService nationService;

    @Autowired
    IPositionService positionService;

    // 查询所有员工返回列表页面
    @GetMapping("/emps")
    public String list(Model model,@RequestParam(value="pageNum",defaultValue="1") Integer pageNum) {
//        List<Emp> emps = empService.getAllEmps();
//        List<Emp> emps = empService.getEmpAndDept();

        // 放在请求域中
//        model.addAttribute("emps",emps);
        // thymleaf默认就会拼串
        // classpath:/templates/xxx.html
        if(ObjectUtils.isEmpty(pageNum)){
            pageNum= PaginationConstant.CURRENT_NUM;
        }
        //设置分页(当前页,和每页显示数据条数)
        PageHelper.startPage(pageNum, PaginationConstant.PAGE_SIZE);

        //查找数据
        List<Emp> emps = empService.getEmpAndDept();
        //将查找出的结果封装到PageInfo对象中,这个对象包含了 emps集合和关于分页的方法,如下
        //pageInfo.getPageNum();
        //pageInfo.getPages(); 得到总页数
        //pageInfo.getNextPage(); 得到下一页
        //pageInfo.getPrePage(); 得到前一页
        PageInfo<Emp> pageInfo=new PageInfo<>(emps);
        // model.addAttribute("emps",emps);
后面还有 82 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。