springboot系列十五、springboot集成PageHelper


一、介紹

項目中經常會遇到分頁,PageHelper為我們解決了這個問題。本質上實現了Mybatis的攔截器,作了分頁處理。

二、配置PageHelper

1、引入依賴

pagehelper-spring-boot-starter對了pagehelper做了封裝,減少 了配置文件,只需要在yml添加就能使用。

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.3</version>
</dependency>

2、配置yml

pagehelper:
    helperDialect: mysql
    reasonable: true #開啟優化,<1頁返回第一頁
    supportMethodsArguments: true #是否支持接口參數來傳遞分頁參數,默認false
    pageSizeZero: false #pageSize=0 返回所有
    params: count=countSql

3、使用示例

    @Test
    public void getAllUserByPage(){
        PageHelper.startPage(1,2);
        System.out.println(userDao.findAll());
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM