小編這次要給大家分享的是SpringBoot中分頁插件PageHelper無效怎么辦,文章內容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。
在Springboot項目中使用分頁插件的時候 發現PageHelper插件失效了
我導入的是:
后來才發
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.10</version> </dependency>
現 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項目同時開發,兩個項目都依賴了Mybatis框架里的pagehelper分頁插件,但是SpringBoot項目分頁不起作用,一直查詢出所有數據。
錯誤原因:兩項目都引入的依賴為
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.0.0</version> </dependency>
解決辦法:經過多次調查試驗,發現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無效怎么辦的文章,如果覺得文章內容寫得不錯的話,可以把它分享出去給更多人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。