目录

- <plugins>
- <plugin interceptor="com.github.pagehelper.PageInterceptor"/>
- plugins>




- @Test
- public void selectplugin() throws Exception{
- //1.加载核心配置文件
- InputStream is = Resources.getResourceAsStream("MybatisConfig.xml");
- //2.获取SqlSession工厂对象
- SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
- //3.通过工厂对象获取SqlSession
- SqlSession sqlSession = sqlSessionFactory.openSession(true);
- //4.获取StudentMapper接口的实现类对象
- StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
- //第一页,显示1条数据
- //PageHelper.startPage(1,1);
- //第二页,显示1条数据
- PageHelper.startPage(2,1);
-
- List
list = mapper.selectAll(); - for(Student student : list){
- System.out.println(student);
- }
- sqlSession.close();
- is.close();
- }


- @Test
- public void selectplugin() throws Exception{
- //1.加载核心配置文件
- InputStream is = Resources.getResourceAsStream("MybatisConfig.xml");
- //2.获取SqlSession工厂对象
- SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
- //3.通过工厂对象获取SqlSession
- SqlSession sqlSession = sqlSessionFactory.openSession(true);
- //4.获取StudentMapper接口的实现类对象
- StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
- //第一页,显示1条数据
- //PageHelper.startPage(1,1);
- //第二页,显示1条数据
- PageHelper.startPage(2,1);
-
- List
list = mapper.selectAll(); - for(Student student : list){
- System.out.println(student);
- }
- //获取分页相关参数
- PageInfo
info = new PageInfo<>(list); - System.out.println("总条数:"+info.getTotal());
- System.out.println("总页数:"+info.getPages());
- System.out.println("当前页:"+info.getPageNum());
- System.out.println("每页显示条数:"+info.getPageSize());
- System.out.println("上一页:"+info.getPrePage());
- System.out.println("下一页:"+info.getNextPage());
- System.out.println("是否是第一页:"+info.isIsFirstPage());
- System.out.println("是否是最后一页:"+info.isIsLastPage());
- sqlSession.close();
- is.close();
- }