Spring Boot 中PageHelper 插件使用配置思路詳解
使用思路
1.引入myabtis和pagehelper依賴
2.yml中配置mybatis掃描和實(shí)體類
這2行代碼
pageNum:當(dāng)前第幾頁(yè)
pageSize:顯示多少條數(shù)據(jù)
userList:數(shù)據(jù)庫(kù)查詢的數(shù)據(jù)數(shù)據(jù)列表
PageHelper.startPage(pageNum, pageSize);
PageInfo pageInfo = new PageInfo(userList);
最后返回一個(gè)pageInfo 對(duì)象即可,pageInfo 這個(gè)對(duì)象中只有數(shù)據(jù)一些信息,但是,沒(méi)有成功失敗的狀態(tài)或者提示語(yǔ)。
真實(shí)企業(yè)中會(huì)封裝一個(gè)返回對(duì)象,把pageInfo 放到對(duì)象中
1.pom依賴
方法一:使用原生的PageHelper
1.在pom.xml中引入依賴,刷新自動(dòng)加載jar
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.1</version>
</dependency>
方法二 本人使用 PageHelper的starter
1.導(dǎo)入pom.xml依賴
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
2.在application.properties或者application.yml格式配置pagehelper的屬性
二選一
#pagehelper分頁(yè)插件配置application.properties
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
application.yml
hepagehelper:
lperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
Controller層調(diào)用 測(cè)試
@RequestMapping("findallCar")
public String findallCar(Model model, HttpSession session) {
PageHelper.startPage(1,5);
List<CarTable> carTables = service.findallCar();
PageInfo<CarTable> page = new PageInfo<CarTable>(carTables);
System.out.println(page);
model.addAttribute("carall", carTables);
session.setAttribute("caralls", carTables);
return "carinsert";
}
PageHelper.startPage(1,5);
List<CarTable> carTables = service.findallCar();
PageInfo<CarTable> page = new PageInfo<CarTable>(carTables);
System.out.println(page);
到此這篇關(guān)于Spring Boot 中PageHelper 插件使用配置思路詳解的文章就介紹到這了,更多相關(guān)Spring Boot PageHelper 插件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談springfox-swagger原理解析與使用過(guò)程中遇到的坑
本篇文章主要介紹了淺談springfox-swagger原理解析與使用過(guò)程中遇到的坑,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
詳解Spring boot+CXF開(kāi)發(fā)WebService Demo
這篇文章主要介紹了詳解Spring boot+CXF開(kāi)發(fā)WebService Demo,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-05-05
Caused by: java.lang.ClassNotFoundException: org.objectweb.a
這篇文章主要介紹了Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type異常,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
Mybatis-Plus字段策略FieldStrategy的使用
本文主要介紹了Mybatis-Plus字段策略FieldStrategy的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
java 鍵盤(pán)輸入一個(gè)數(shù),輸出數(shù)組中指定元素的示例
今天小編就為大家分享一篇java 鍵盤(pán)輸入一個(gè)數(shù),輸出數(shù)組中指定元素的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
springboot整合企微webhook機(jī)器人發(fā)送消息提醒
這篇文章主要為大家介紹了springboot整合企微webhook機(jī)器人發(fā)送消息提醒,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
值得收藏!教你如何在IDEA中快速查看Java字節(jié)碼
開(kāi)發(fā)中如果我們想看JVM虛擬機(jī)怎么編譯我們的Java文件,生成字節(jié)碼的,用IDEA工具就可以查看,本篇文章就給大家詳細(xì)介紹,對(duì)正在學(xué)習(xí)java的小伙伴們很有幫助,需要的朋友可以參考下2021-05-05
解決mybatis plus 分頁(yè)查詢有條數(shù),total和pages都是零的問(wèn)題
這篇文章主要介紹了解決mybatis plus 分頁(yè)查詢有條數(shù),total和pages都是零的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11

