<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.8</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-autoconfigure</artifactId> <version>1.2.10</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency>
mybatis分頁需要引入的依賴
最近看到分頁插件pageHelper 會有效率問題
大多數人跟我一樣,最開始接觸PageHelper的時候,都被超級方便的分頁操作吸引
有多方便?
public PageInfo querySharePage(QueryObject qo) { PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize()); List<ShareTrainHh> shareList = trainHhMapper.selectAll(); return new PageInfo(shareList); }
一個普通的分頁功能,從頭到尾只需要三句代碼
配置文件:
如果使用單數據源,可在配置文件中配置如下:
pagehelper:
helperDialect: mysql
reasonable: false
supportMethodsArguments: true
params: count=countSql
如果使用多數據源,需要修改pagehelper配置項,配置如下
pagehelper:
# helperDialect: mysql
reasonable: false
supportMethodsArguments: true
params: count=countSql
# 默認false,當為true時,自動檢驗適合的數據庫
auto-dialect: true
# 這個一定要加上,不然mysql和sqlserver分頁兩個只能用一個,另一個會報錯,加上后,兩中數據庫分頁都可以用了
auto-runtime-dialect: true
但是!
數據量大一點的表,千萬不要隨便拿來就用!
作者:燭火下的烏托邦丶
參考原文鏈接:https://www.jianshu.com/p/88d1eca40271