springboot系列十5、springboot集成PageHelper

1、介紹

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

2、配置PageHelper

一、引入依賴

pagehelper-spring-boot-starter對了pagehelper作了封裝,減小 了配置文件,只須要在yml添加就能使用。git

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

二、配置yml

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

三、使用示例

    @Test
    public void getAllUserByPage(){
        PageHelper.startPage(1,2);
        System.out.println(userDao.findAll());
    }
相關文章
相關標籤/搜索