歡迎您光臨本站 註冊首頁

SpringBoot項目中分頁插件PageHelper無效的問題及解決方法

←手機掃碼閱讀     zhang3221994 @ 2020-06-11 , reply:0

在Springboot項目中使用分頁插件的時候 發現PageHelper插件失效了

我導入的是:

後來才發

  com.github.pagehelperpagehelper5.1.10

 

現 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啟動器 無需注入 開箱即用 更推薦此方法:

  com.github.pagehelperpagehelper-spring-boot-starter1.2.10

 

PS:SpringBoot項目和Spring項目依賴分頁插件Pagehelper不起作用的問題

最近在SpringBoot項目和Spring項目同時開發,兩個項目都依賴了Mybatis框架裡的pagehelper分頁插件,但是SpringBoot項目分頁不起作用,一直查詢出所有數據。

錯誤原因:兩項目都引入的依賴為

   com.github.pagehelperpagehelper4.0.0

 

解決辦法:經過多次調查試驗,發現SpringBoot項目依賴的分頁插件和Spring項目有所不同,需要spring-boot-starter下的包才可以。所以SpringBoot項目需要配置下面的依賴即可:

   com.github.pagehelperpagehelper-spring-boot-starter1.2.5



[zhang3221994 ] SpringBoot項目中分頁插件PageHelper無效的問題及解決方法已經有241次圍觀

http://coctec.com/docs/java/show-post-238093.html