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<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