1. package com.wzy.controller;
    2. import com.github.pagehelper.PageHelper;
    3. import com.github.pagehelper.PageInfo;
    4. import com.wzy.pojo.Employee;
    5. import com.wzy.pojo.Msg;
    6. import com.wzy.service.EmployeesService;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.stereotype.Controller;
    9. import org.springframework.ui.Model;
    10. import org.springframework.web.bind.annotation.RequestMapping;
    11. import org.springframework.web.bind.annotation.RequestParam;
    12. import org.springframework.web.bind.annotation.ResponseBody;
    13. import java.util.List;
    14. @Controller
    15. public class EmployeeController {
    16. @Autowired
    17. EmployeesService employeesService;
    18. @RequestMapping(value = "/list")
    19. @ResponseBody//使用jackson依赖后,可以将返回值,自动转为json
    20. public Msg getEmployeeWithJson(@RequestParam(value = "pageNumber",defaultValue = "1") Integer pageNumber,
    21. Model model){
    22. /**
    23. *pageNumber动态获取第几页
    24. *5 此处固定每页显示5条数据
    25. */
    26. PageHelper.startPage(pageNumber,5);//这方法下的 执行sql的方法 会分页。
    27. List<Employee> employeesList = employeesService.getEmployeeAll();
    28. /**
    29. * 使用pageInfo 包装查询到的信息,只需要将 使用pageInfo 交给 跳转输出页面
    30. * 封装了详细的分页信息。包括我们查询出来的数据
    31. * 第一个参数是封装查询到的结果,第二个参数是要连续显示的页数
    32. */
    33. PageInfo pageInfo = new PageInfo(employeesList);
    34. //返回 pageInfo 的json
    35. return Msg.success().add("pageInfo",pageInfo);
    36. }
    37. }

    浏览器访问结果http://localhost:8080/SSM/list

    image.png