pagehelper插件顯示total為-1或1的問題
簡單講下用法:
//引依賴 <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>2.1.5</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency>
//使用步驟 PageHelper.startPage(page,limit,true); PageInfo<對應實體類> pageInfo = new PageInfo(對應實體類查出的list查出所有);
首先total為-1的問題:上面添加分頁參數(shù)時要加上true,判斷是否輸出真實的總數(shù)
total為1:分頁插件對應的方法應該緊跟在PageHelper.startPage下一行,中間不能插入其他方法。
yml可以加上這些配置參數(shù)
pagehelper: # dialect: ① # 分頁插件會自動檢測當前的數(shù)據(jù)庫鏈接,自動選擇合適的分頁方式(可以不設置) helper-dialect: oracle # 上面數(shù)據(jù)庫設置后,下面的設置為true不會改變上面的結果(默認為true) auto-dialect: true page-size-zero: false # ② reasonable: true # ③ # 默認值為 false,該參數(shù)對使用 RowBounds 作為分頁參數(shù)時有效。(一般用不著) offset-as-page-num: false # 默認值為 false,RowBounds是否進行count查詢(一般用不著) row-bounds-with-count: false #params: ④ #support-methods-arguments: 和params配合使用,具體可以看下面的講解 # 默認值為 false。設置為 true 時,允許在運行時根據(jù)多數(shù)據(jù)源自動識別對應方言的分頁 auto-runtime-dialect: false # ⑤ # 與auto-runtime-dialect配合使用 close-conn: true # 用于控制默認不帶 count 查詢的方法中,是否執(zhí)行 count 查詢,這里設置為true后,total會為-1 default-count: false #dialect-alias: ⑥
ps:PageHelper新手使用教程
剛剛使用了PageHelper分頁工具,簡單寫一下
如果是SpringBoot工程,大家可以省略第一步
1.首先先配置一下mybatis.xml文件,然后再配置文件中寫入以下代碼
<plugins> <plugin interceptor="com.github.pagehelper.PageInterceptor" /> </plugins>
2.其實就可以在Controller里調(diào)用PageHelper
public Result getall(@RequestParam(value="page",defaultValue="1")Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
//這個一定要放在第一行,否則無法進行分頁
PageHelper.startPage(page,limit);
List<User> userList =userService.getAll();
//分頁
PageInfo pageInfo = new PageInfo(userList);
//pageInfo.getTotal數(shù)據(jù)總條數(shù)
return Result.success(userList ,pageInfo .getTotal());
}
總結
到此這篇關于pagehelper插件顯示total為-1或1的文章就介紹到這了,更多相關pagehelper插件顯示total為-1或1內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Spring Bean生命周期之BeanDefinition的合并過程詳解
這篇文章主要為大家詳細介紹了Spring Bean生命周期之BeanDefinition的合并過程,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-03-03
Springboot多環(huán)境開發(fā)及使用方法
這篇文章主要介紹了Springboot多環(huán)境開發(fā)及多環(huán)境設置使用、多環(huán)境分組管理的相關知識,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03
解決SpringBoot使用devtools導致的類型轉(zhuǎn)換異常問題
這篇文章主要介紹了解決SpringBoot使用devtools導致的類型轉(zhuǎn)換異常問題,具有很好的參考價值,希望對大家有所幫助。 一起跟隨小編過來看看吧2020-08-08

