Mybatis分页插件

1.添加POM依赖
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.2.0</version>
</dependency>
2.插件注册
<plugins>
   <plugin interceptor="com.github.pagehelper.PageInterceptor">
       <property name="helperDialect" value="mysql"/>
       <property name="offsetAsPageNum" value="false"/>
       <property name="rowBoundsWithCount" value="false"/>
       <property name="pageSizeZero" value="true"/>
       <property name="reasonable" value="true"/>
   </plugin>
</plugins>
3.调用
//  创建Page对象,将pageNum,pageSize参数传入,必须位于从数据库查询数据的语句之前,否则不生效
Page<Object> page = PageHelper.startPage(pageNum, pageSize);
List<UserPrivileges> list = userPrivilegesDao.selectAll();
// 获取查询记录总数,必须位于从数据库查询数据的语句之后,否则不生效
long total = page.getTotal();
logger.debug("总共条数: " + total);
return list;
4.执行log
16:56:46.859 [http-nio-8080-exec-6] DEBUG com.vidor.dao.UserPrivilegesDao.selectAll_COUNT - ==>  Preparing: SELECT count(0) FROM USER_PRIVILEGES
16:56:46.882 [http-nio-8080-exec-6] DEBUG com.vidor.dao.UserPrivilegesDao.selectAll_COUNT - ==> Parameters: 
16:56:46.892 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll_COUNT - <==    Columns: count(0)
16:56:46.892 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll_COUNT - <==        Row: 30
16:56:46.894 [http-nio-8080-exec-6] DEBUG com.vidor.dao.UserPrivilegesDao.selectAll_COUNT - <==      Total: 1
16:56:46.896 [http-nio-8080-exec-6] DEBUG com.vidor.dao.UserPrivilegesDao.selectAll - ==>  Preparing: select GRANTEE, TABLE_CATALOG, PRIVILEGE_TYPE, IS_GRANTABLE from USER_PRIVILEGES LIMIT ?
16:56:46.896 [http-nio-8080-exec-6] DEBUG com.vidor.dao.UserPrivilegesDao.selectAll - ==> Parameters: 10(Integer)
16:56:46.897 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==    Columns: GRANTEE, TABLE_CATALOG, PRIVILEGE_TYPE, IS_GRANTABLE
16:56:46.897 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, SELECT, YES
16:56:46.897 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, INSERT, YES
16:56:46.897 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, UPDATE, YES
16:56:46.898 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, DELETE, YES
16:56:46.898 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, CREATE, YES
16:56:46.898 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, DROP, YES
16:56:46.898 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, RELOAD, YES
16:56:46.898 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, SHUTDOWN, YES
16:56:46.898 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, PROCESS, YES
16:56:46.899 [http-nio-8080-exec-6] TRACE com.vidor.dao.UserPrivilegesDao.selectAll - <==        Row: 'root'@'localhost', def, FILE, YES
16:56:46.899 [http-nio-8080-exec-6] DEBUG com.vidor.dao.UserPrivilegesDao.selectAll - <==      Total: 10
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值