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);
}
本文介绍了如何使用PageHelper,一个MyBatis的高效分页插件。首先,你需要在项目中添加PageHelper的jar包,并在MyBatis的配置文件中配置插件。然后,在Java代码中调用PageHelper.startPage()方法进行分页查询,如示例所示,设置PageNum和PageSize参数,最后执行查询并打印结果。这个插件简化了MyBatis的分页操作,提高了开发效率。
5万+

被折叠的 条评论
为什么被折叠?



