參考:https://github.com/pagehelper/Mybatis-PageHelper/issues/417
問題:
使用環境
PageHelper 版本: pagehelper-spring-boot-starter1.2.12
資料庫類型和版本: 5.7
*配置:
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
PageHelper.startPage(pageNum, pageSize);
List list = xxxMapper.getxxx(userId, status);
for(list){}
PageInfo pageInfo = new PageInfo(result);
當我調用時分頁後,對傳回的list進行了循環(因為要特殊處理某些字段),然後在使用PageInfo封裝分頁結果時發現錯誤:
資料庫中有20條資料,
當pageNum=1,pageSize=50時,結果與期望相符
當pageNum=1,pageSize=10時,total為10,頁數為1
解決思路:
解決辦法:
使用PageHelper分頁,不可以将資料庫中查出來的list轉為其他list,可以直接封裝DTO在資料庫中直接傳回你需要的資料類型,不要查詢出來之後再去轉換,這樣會導緻PageHelper中pageInfo失效。