PageHelper : MyBatis通用分页插件(实用)
使用 :
首先 , 添加PageHelper的jar包
<!--使用PageHelper的jar包-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
</dependency>
(2) 加入plugin配置 :
注意是在主配置文件中添加的 , 而不是添加在pom.xml文件中
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
java中编写 :
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao studentDao = sqlSession.getMapper(StudentDao.class);
/*加入分页查询的数据
其中PageNum : 第几页数据(为0的话就查不出来数据了)
PageSize : 一页中有多少行数据
* */
/*PageHelper.startPage(PageNum,PageSize);*/
PageHelper.startPage(2,3);
List<Student> studentList = studentDao.selectAllTwo();
for (Student student : studentList) {
System.out.println(student);
}