PageHelper插件

来源:互联网 发布:淘宝上怎么买弓弩 编辑:程序博客网 时间:2024/06/12 19:11

在使用ssm框架时处理业务逻辑时,会有分页的需求,mybatis可以使用插件,PageHelper就是一个分页插件:
该插件支持的数据库:

  • Oracle
  • Mysql
  • MariaDB
  • SQLite
  • Hsqldb
  • PostgreSQL

在mabatis的配置文件中引入该插件即可使用:

<plugins>    <plugin interceptor="com.github.pagehelper.PageInterceptor">        <!-- config params as the following -->        <property name="dialect" value="数据库类型"/>    </plugin></plugins>

property属性指定的dialect表示:

使用PageHelper的默认分页,如果您想实现自己的页面逻辑,您可以实现com.github.pagehelper.Dialect接口,然后将属性配置为实现类的完全限定名。


使用方法有多种,最简单的是使用它的静态方法:
PageHelper.startPage(startnum,rows);
startnum表示页码从即开始;
rows表示每页的记录数。


List list = itemMapper.selectByExample(example);
PageInfo pageInfo = new PageInfo<>(list);
PageInfo是一个类,创建对象时需要传入一个类型,存储查询结果的list。
PageInfo中还有一些方法用于获取分页信息,比如:
pageInfo.getPages();
pageInfo.page.getPageSize()

原创粉丝点击