MyBatis中如何使用PageHelper插件实现 分页

来源:互联网 发布:亨通大数据产业园 编辑:程序博客网 时间:2024/06/05 07:31

首先  第一步在mybatis配置文件中 配置分页插件

<plugins>
<!-- 分页插件:com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 方言 -->
<property name="dialect" value="mysql" />
<!-- 该参数默认为false -->
<!-- 设置为true时,使用RowBounds分页会进行count查询,查询数据总条数 -->
<property name="rowBoundsWithCount" value="true" />
</plugin>


在controller中  开启分页 

PageHelper.startPage(page, rows); // 分页开始   之后第一条sql语句被拦截拼接limit

List<Item> itemList = itemService.queryItemList(); // 被拦截后sql语句就拼接limit

PageInfo<Item> pageInfo = new PageInfo<Item>(itemList); //


pageInfo 对象中 有我们想要的所有信息! 很简易方便