springboot如何集成pagehelper

這篇文章主要為大家展示了“spring boot如何集成pagehelper”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“spring boot如何集成pagehelper”這篇文章吧。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了秀峰免費(fèi)建站歡迎大家使用!

當(dāng)spring boot集成好mybatis時(shí)候需要進(jìn)行分頁(yè),我們首先添加maven支持

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

方式一:我們?cè)赼pplication.yml(spring 需要讀取的yml)中加入

pagehelper:
 helperDialect: MySQL
 reasonable: true
 supportMethodsArguments: true
 params: count=countSql

然后重啟即可。

配置文件最終會(huì)被java所讀取,最終注入到spring bean中,所以我們方法二是配置其bean類,熱加載方便修改當(dāng)然方式一更簡(jiǎn)單,

方式二:在注解涵蓋package下面新建PageHeleperConfig

import com.github.pagehelper.PageHelper;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhuxiaomeng
 * @date 2018/1/2.
 * @email 154040976@qq.com
 */
@Configuration
public class PageHelperConfig {


 @Bean
 public PageHelper getPageHelper(){
 PageHelper pageHelper=new PageHelper();
 Properties properties=new Properties();
 properties.setProperty("helperDialect","mysql");
 properties.setProperty("reasonable","true");
 properties.setProperty("supportMethodsArguments","true");
 properties.setProperty("params","count=countSql");
 pageHelper.setProperties(properties);
 return pageHelper;
 }

}

pageHelper 基礎(chǔ)知識(shí)為:

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
Page<T> tPage= PageHelper.startPage(page,limit);

下一句的查詢語(yǔ)句來進(jìn)行分頁(yè)。你只需要用List<T>接收

以上是“spring boot如何集成pagehelper”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

本文題目:springboot如何集成pagehelper
轉(zhuǎn)載注明:http://muchs.cn/article32/ijdopc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、微信公眾號(hào)、網(wǎng)站策劃、全網(wǎng)營(yíng)銷推廣、服務(wù)器托管手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)