SpringBoot項目中分頁插件PageHelper無效的問題及解決方法
在Springboot項目中使用分頁插件的時候 發(fā)現(xiàn)PageHelper插件失效了
我導入的是:
后來才發(fā)
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.10</version> </dependency>
現(xiàn) PageHelper若要在Springboot中使用 是需要進行注入的:
@Configuration public class mybatisConfiguration { @Bean public PageHelperpageHelper(){ System.out.println("MybatisConfiguration.pageHelper()"); PageHelper pageHelper =new PageHelper(); Properties properties =new Properties(); properties.setProperty("offsetAsPageNum","true"); properties.setProperty("rowBoundsWithCount","true"); properties.setProperty("reasonable","true"); pageHelper.setProperties(properties); return pageHelper; } }
當然 也可使用Springboot PageHelper啟動器 無需注入 開箱即用 更推薦此方法:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency>
PS:SpringBoot項目和Spring項目依賴分頁插件Pagehelper不起作用的問題
最近在SpringBoot項目和Spring項目同時開發(fā),兩個項目都依賴了Mybatis框架里的pagehelper分頁插件,但是SpringBoot項目分頁不起作用,一直查詢出所有數(shù)據(jù)。
錯誤原因:兩項目都引入的依賴為
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.0.0</version> </dependency>
解決辦法:經(jīng)過多次調(diào)查試驗,發(fā)現(xiàn)SpringBoot項目依賴的分頁插件和Spring項目有所不同,需要spring-boot-starter下的包才可以。所以SpringBoot項目需要配置下面的依賴即可:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.5</version> </dependency>
總結
到此這篇關于SpringBoot項目中分頁插件PageHelper無效的問題及解決方法的文章就介紹到這了,更多相關SpringBoot分頁插件PageHelper無效內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringBoot自定義線程池,執(zhí)行定時任務方式
這篇文章主要介紹了SpringBoot自定義線程池,執(zhí)行定時任務方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-04-04java.sql.Date和java.util.Date的區(qū)別詳解
Java中有兩個Date類,一個是java.util.Date通常情況下用它獲取當前時間或構造時間,另一個是java.sql.Date是針對SQL語句使用的,它只包含日期而沒有時間部分,這篇文章主要給大家介紹了關于java.sql.Date和java.util.Date區(qū)別的相關資料,需要的朋友可以參考下2023-03-03