Mybatis–关于分页查询插件的使用
1.概念
1.1 分页插件
mybatis的一个分页插件,即一个负责分页的jar包
1.2 相关jar包
jsqlparser…jar
pagehelper…jar
2.步骤
2.1 导包
2.2 核心配置文件
这里需要注意的是5.x和4.x的配置是不同的
在4.x及以下版本中,mybatis-config.xml中的配置为:
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
<property name="rowBoundsWithCount" value="true"/>
</plugin>
</plugins>
在5.x版本,mybatis-config.xml中配置pageHelper的格式为:
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
</plugins>
(ps:至于 property标签中的配置 是用来那啥的,我也不是很清楚,希望懂的大佬能帮忙解释一下.)
2.3 使用PageHelper设置分页,并将结果封装成PageInfo对象(非必须,但基本全这样做)
记得一定要在查询数据前设置
其中selectAllStudentInfo()方法可以调用所有查询到的学生信息,并存储在了数组students中,但由于PageHelper仅显示当前页的数据
3.补充
PageInfo对象部分功能
System.out.println("总行数:"+page.getTotal());
System.out.println("总页数:"+page.getPages());
System.out.println("当前页:" + page.getPageNum());
System.out.println("每页显示的行数:" + page.getPageSize());
System.out.println("上一页(页数):" + page.getPrePage());
System.out.println("下一页(页数):" + page.getNextPage());
System.out.println("是否是第一页:" + page.isIsFirstPage());
System.out.println("是否是最后一页:" + page.isIsLastPage());