Spring Boot 中PageHelper 插件使用配置思路詳解
使用思路
1.引入myabtis和pagehelper依賴
2.yml中配置mybatis掃描和實(shí)體類
這2行代碼
pageNum:當(dāng)前第幾頁
pageSize:顯示多少條數(shù)據(jù)
userList:數(shù)據(jù)庫查詢的數(shù)據(jù)數(shù)據(jù)列表
PageHelper.startPage(pageNum, pageSize);
PageInfo pageInfo = new PageInfo(userList);
最后返回一個(gè)pageInfo 對象即可,pageInfo 這個(gè)對象中只有數(shù)據(jù)一些信息,但是,沒有成功失敗的狀態(tài)或者提示語。
真實(shí)企業(yè)中會(huì)封裝一個(gè)返回對象,把pageInfo 放到對象中
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分頁插件配置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)用 測試
@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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot實(shí)現(xiàn)緩存組件配置動(dòng)態(tài)切換的步驟詳解
現(xiàn)在有多個(gè)springboot項(xiàng)目,但是不同的項(xiàng)目中使用的緩存組件是不一樣的,有的項(xiàng)目使用redis,有的項(xiàng)目使用ctgcache,現(xiàn)在需要用同一套代碼通過配置開關(guān),在不同的項(xiàng)目中切換這兩種緩存,本文介紹了SpringBoot實(shí)現(xiàn)緩存組件配置動(dòng)態(tài)切換的步驟,需要的朋友可以參考下2024-07-07
一些java二進(jìn)制的相關(guān)基礎(chǔ)知識
這篇文章主要介紹了一些java二進(jìn)制的相關(guān)基礎(chǔ)知識,在Java語言中byte代表最小計(jì)量單位,byte由8位2進(jìn)制數(shù)組成。,需要的朋友可以參考下2019-06-06
java8升級到j(luò)ava17的兼容性分析與遷移指南
這篇文章主要為大家詳細(xì)介紹了從?Java?8?升級到?Java?17?的詳細(xì)分析和遷移步驟,包括代碼修改建議,依賴更新和配置調(diào)整,有需要的小伙伴可以參考一下2025-04-04
Springboot整合Netty自定義協(xié)議實(shí)現(xiàn)示例詳解
這篇文章主要為大家介紹了Springboot整合Netty自定義協(xié)議實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
java虛擬機(jī)鉤子關(guān)閉函數(shù)addShutdownHook的操作
這篇文章主要介紹了java虛擬機(jī)鉤子關(guān)閉函數(shù)addShutdownHook的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-02-02
在logback.xml中自定義動(dòng)態(tài)屬性的方法
這篇文章主要介紹了在logback.xml中自定義動(dòng)態(tài)屬性的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08

