springBoot項目使用pagehelper分頁插件

首先需要通過maven導入pagehelper分頁插件,在pom.xml文件中加入pagehelper依賴;

使用spring時加入以下依賴:

        <!-- 分頁插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>

使用springboot是要加入以下依賴:

        <!--分頁插件 -->
        <dependency>
             <groupId>com.github.pagehelper</groupId>
             <artifactId>pagehelper-spring-boot-starter</artifactId>
             <version>1.2.3</version>
        </dependency>

使用分頁插件獲取數據:


 @RequestMapping("getPageByCondition")
 @ResponseBody
 public Object getPageByCondition(Invesitagion condition) {
    
     PageHelper.startPage(condition.getPage(), condition.getLimit(), true); //執行分頁查詢
     PageInfo<Invesitagion>  pageInfo = new PageInfo<Invesitagion>((Page) infoService.getPageByCondition(condition));//執行查詢語句
     return new ResultLayuiPage(pageInfo);//返回json數據
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章