Spring Boot 中PageHelper 插件使用配置思路詳解
1.引入myabtis和pagehelper依賴(lài)
2.yml中配置mybatis掃描和實(shí)體類(lèi)
這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依賴(lài)方法一:使用原生的PageHelper
1.在pom.xml中引入依賴(lài),刷新自動(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依賴(lài)
<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=mysqlpagehelper.reasonable=truepagehelper.support-methods-arguments=truepagehelper.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)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. .NET使用YARP通過(guò)編碼方式配置域名轉(zhuǎn)發(fā)實(shí)現(xiàn)反向代理2. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法3. django Layui界面點(diǎn)擊彈出對(duì)話框并請(qǐng)求邏輯生成分頁(yè)的動(dòng)態(tài)表格實(shí)例4. AJAX原理以及axios、fetch區(qū)別實(shí)例詳解5. Django 如何從request中獲取前端數(shù)據(jù)6. 使用FormData進(jìn)行Ajax請(qǐng)求上傳文件的實(shí)例代碼7. javascript設(shè)計(jì)模式 ? 組合模式原理與應(yīng)用實(shí)例分析8. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享9. Ajax常用封裝庫(kù)——Axios的使用10. ASP.NET Identity的基本用法
