DepartmentController:

    1. package com.wzy.controller;
    2. import com.github.pagehelper.PageInfo;
    3. import com.wzy.pojo.Department;
    4. import com.wzy.pojo.Msg;
    5. import com.wzy.service.DepartmentService;
    6. import org.springframework.stereotype.Controller;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.ResponseBody;
    9. import java.util.List;
    10. @Controller
    11. public class DepartmentController {
    12. private DepartmentService departmentService;
    13. @ResponseBody//使用jackson依赖后,可以将返回值,自动转为json
    14. @RequestMapping(value = "/departement")
    15. public Msg getDepart(){
    16. List<Department> departments = departmentService.getDepartment();
    17. /**
    18. * 使用pageInfo 包装查询到的信息,只需要将 使用pageInfo 交给 跳转输出页面
    19. * 封装了详细的分页信息。包括我们查询出来的数据
    20. * 第一个参数是封装查询到的结果,第二个参数是要连续显示的页数
    21. */
    22. PageInfo pageInfo = new PageInfo(departments);
    23. //返回 pageInfo 的json
    24. return Msg.success().add("pageInfo",pageInfo);
    25. }
    26. }

    DepartmentService:

    1. package com.wzy.service;
    2. import com.wzy.dao.DepartmentMapper;
    3. import com.wzy.pojo.Department;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Service;
    6. import java.util.List;
    7. @Service
    8. public class DepartmentService {
    9. @Autowired
    10. DepartmentMapper departmentMapper;
    11. public List<Department> getDepartment(){
    12. //按条件查询,参数为 null 查询所有。
    13. List<Department> departments = departmentMapper.selectByExample(null);
    14. return departments;
    15. }
    16. }