1. package com.wzy;
    2. import com.baomidou.mybatisplus.plugins.Page;
    3. import com.wzy.mapper.EmployeesMapper;
    4. import com.wzy.pojo.Employees;
    5. import org.junit.Test;
    6. import org.springframework.context.ApplicationContext;
    7. import org.springframework.context.support.ClassPathXmlApplicationContext;
    8. import java.util.List;
    9. public class testPage {
    10. //1.读取applicationContext.xml
    11. private ApplicationContext applicationContext =
    12. new ClassPathXmlApplicationContext("applicationContext.xml");
    13. //2.根据applicationContext.xml配置文件与反射,获取 EmployeesMapper对象
    14. private EmployeesMapper employeesMapper =
    15. applicationContext.getBean("employeesMapper",EmployeesMapper.class);
    16. @Test
    17. public void test1(){
    18. Page<Employees> page = new Page<Employees>(1, 3);
    19. List<Employees> list = employeesMapper.selectPage(page, null);
    20. list.forEach(employee -> System.out.println(employee));
    21. System.out.println("总条数: " + page.getTotal());
    22. System.out.println("当前页码: " + page.getCurrent());
    23. System.out.println("总页码: " + page.getPages());
    24. System.out.println("每页显示的条数: " + page.getSize());
    25. System.out.println("是否有上一页: " + page.hasPrevious());
    26. System.out.println("是否有下一页: " + page.hasNext());
    27. //将查询结果封装为Page对象
    28. Page<Employees> employeesPage = page.setRecords(list);
    29. //将Page对象,转为list结果集
    30. List<Employees> records = employeesPage.getRecords();
    31. }
    32. }

    输出结果:

    Employees(id=1, lastName=Tom, email=tom@atguigu.com, gender=1, age=22) Employees(id=2, lastName=Jerry, email=jerry@atguigu.com, gender=0, age=25) Employees(id=3, lastName=Black, email=black@atguigu.com, gender=1, age=30) 总条数: 7 当前页码: 1 总页码: 3 每页显示的条数: 3 是否有上一页: false 是否有下一页: true