Mybatis插件:PageHelper的使用
1. 在pom.xml配置PageHelper的依赖信息
<!--添加pageHelper的依赖-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
2. 在主配置文件中配置插件信息
<!--配置插件,必须在环境的配置新奇前面-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
3. 在测试程序中使用PageHelper
@Test
public void testSelectStudents(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
PageHelper.startPage(1,3);
List<Student> list = dao.selectStudents();
for(Student stu :list ){
System.out.println(stu);
}
}

浙公网安备 33010602011771号