1. 程式人生 > >Mybatis物理分頁外掛PageHelper 5.0

Mybatis物理分頁外掛PageHelper 5.0

昨天在Maven管理的專案中整合PageHelper的時候總是沒有成功。我採用的是Spring的整合方式。 
pagehelper
因為我使用的是PageHelper5.0,如果按照這樣的配置的話,Log就會報出如下異常: 
Error creating bean with name ‘sqlSessionFactory’ defined in class path resource 
[META-INF/spring/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: 
Failed to convert property value of type ‘java.lang.Object[]’ to required type ‘org.apache.ibatis.plugin.Interceptor[]’ for property ‘plugins’; 
nested exception is java.lang.IllegalStateException: 
Cannot convert value of type ‘com.github.pagehelper.PageHelper’ to required type ‘org.apache.ibatis.plugin.Interceptor’ for property ‘plugins[0]’: no matching editors or conversion strategy found 
大致意思就是沒辦法轉型成org.apache.ibatis.plugin.Interceptor,在這裡我就不明白了,因為網上的教程基本都是這麼配置的。 
然後我就換一種方式,採用mybatis整合方式進行配置,結果還是出錯。內容描述基本差不多。到這裡我就很納悶了,我還特意開啟原始碼,發現確實有PageHelper這個包啊。 
然後我開啟org.mybatis.spring.SqlSessionFactoryBean找到plugins的具體傳參看見

if (!isEmpty(this.plugins)) {
  for (Interceptor plugin : this.plugins) {
    configuration.addInterceptor(plugin);
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Registered plugin: '" + plugin + "'");
      }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

這裡我發現plugin是Interceptor,沒辦法,只能在github上找最新的PageHelper的文件了。 
突然發現這兒坑還挺多的。下面我就把PageHelper 5.0與以前版本不一樣的地方給貼出來。

  1. 使用 QueryInterceptor 規範 處理分頁邏輯 新的分頁外掛攔截器為 
    com.github.pagehelper.PageInterceptor 新的 PageHelper 是一個特殊的 Dialect
  2. 實現類,以更友好的方式實現了以前的功能 新的分頁外掛僅有 dialect 一個引數,預設的 dialect 實現類為 PageHelper
  3. PageHelper 仍然支援以前提供的引數,在最新的使用文件中已經全部更新 PageHelper 的 helperDialect 引數和以前的 dialect 功能一樣,具體可以看文件的引數說明
  4. 增加了基於純 RowBounds 和 PageRowBounds 的分頁實現,在com.github.pagehelper.dialect.rowbounds 包中,這是用於作為 dialect 引數示例的實現,後面會補充更詳細的文件 去掉了不適合出現在分頁外掛中的 orderby功能,以後會提供單獨的排序外掛
  5. 去掉了PageHelper 中不常用的方法新的文件,更新曆來更新日誌中提到的重要內容,提供英文版本文件 解決 bug 將 Db2RowDialect 改為Db2RowBoundsDialect 所有分頁外掛丟擲的異常改為 PageException

然後他給的Demo中配置是這樣的。

<bean id="sqlSessionFactory"         class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="plugins">
<array>
  ```ruby
  <bean class="com.github.pagehelper.PageInterceptor">
  ```
    <property name="properties">
      <!--使用下面的方式配置引數,一行配置一個 -->
      <value>
        params=value1
      </value>
    </property>
  </bean>
</array>
  </property>
</bean>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

還有一個小坑需要注意的是,在5.0中使用了helperDialect代替了原來的dialect屬性。

相關推薦

Mybatis物理外掛PageHelper 5.0

昨天在Maven管理的專案中整合PageHelper的時候總是沒有成功。我採用的是Spring的整合方式。  因為我使用的是PageHelper5.0,如果按照這樣的配置的話,Log就會報出如下異常:  Error creating bean with name ‘sql

Mybatis外掛-PageHelper(5.0)的使用

轉:http://blog.csdn.net/u012728960/article/details/50791343 maven依賴 <!-- pagehelper分頁外掛 --> <dependency> <groupId>com

2017.12.14 Mybatis物理外掛PageHelper的使用(一)

參考來自: 1.物理分頁和邏輯分頁 1 邏輯分頁 : 邏輯分頁指的是將資料庫中所有資料全部取出,然後通過Java程式碼控制分頁邏輯。 2 物理分頁 : 物理分頁指的是在SQL查詢過程中實現分頁,依託與不同的資料庫廠商,實現也會不同。 2.需求 現在使用的是邏

SpringBoot2.0整合MyBatis外掛PageHelper

PageHelper是MyBatis的一款分頁外掛,支援常見的 12 種資料庫,如Oracle,MySql,MariaDB,SQLite,DB2,PostgreSQL,SqlServer 等,專案

mybatis外掛pagehelper的使用

第一步,新增maven依賴。  第二步,在mybatis外掛中配置pagehelper外掛。這裡以使用mysql資料庫為例。 pagehelper5.0以上版本。 <?xml version="1.0" encoding="UTF-8" ?> <!DOCT

Spring,SpringBoot 整合 MyBatis外掛 PageHelper

SPRING BOOT, Spring整合 MyBatis 的分頁外掛 PageHelper 原創   2018-04-03  宗野   Spring Boot    昨天給各位總結了

Mybatis外掛PageHelper

  外掛官方文件地址:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md 使用方法:https://github.com/pagehelper/Mybatis-PageHelper/bl

springboot+Mybatis外掛pageHelper

1、在pom.xml加入pageHelper依賴包 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>page

spring-boot 整合mybatis外掛PageHelper版本問題

Pagehelper 5.0.0及以上版本。使用的是這個類Pagehelper,我們在專案中可以這樣寫: PageInterceptor pageHelper = new PageInterceptor(); properties.setProperty(“helperDialect”, “

Mybatis外掛PageHelper的原理及使用

PageHelper是一款開源的Mybatis分頁外掛,mysql、 oracle、 mariaDB、 DB2、 SQLite、 Hsqldb等常用資料庫分頁。 一、使用步驟 1.匯入相關jar包或依賴 2.配置攔截器(兩種方式) 2.1第一種在Mybatis的主配置檔案SqlM

Mybatis外掛PageHelper的快速使用

PageHelper實現分頁的快速使用 在實際專案中,經常會用到查詢功能,很多時候都是查詢所得的資料量比較大,難以一次性展示出來。例如查詢本次考試的所有考生資訊,這時候就需要用到分頁功能了,而PageHelper是Mybatis自帶的一個分頁外掛,可用於實現分頁

分析Mybatis外掛PageHelper的原始碼

本次我們分析PageHelper的原始碼,檢視它的執行過程; 1、PageHelper的版本 <dependency> <groupId>com.github.pagehelper</groupId>

Spring Boot系列教程十一: Mybatis使用外掛PageHelper

一.前言 上篇部落格中介紹了spring boot整合mybatis的方法,基於上篇文章這裡主要介紹如何使用分頁外掛PageHelper。在MyBatis中提供了攔截器介面,我們可以使用PageHelp最為一個外掛裝入到SqlSessionFactory,實現攔截器功能。

Mybatis外掛PageHelper使用及注意事項

(一)PageHelper分頁外掛介紹 *筆者採用spring+springMVC+mybatis框架做java後臺開發,開發軟體是IntellijIDEA(用過之後已卸掉eclipse),專案為maven工程。 使用方法 (在已有ssm框架基礎上)

Mybatis外掛PageHelper失效的原因

PageHelper是Mybatis的一個很好的分頁外掛,但要使用它的分頁功能需要注意一下幾點 1.匯入相關包,例如maven匯入依賴 <dependency> <groupId>com.github.pagehelper</gr

mybatis框架---外掛PageHelper的使用方法

以前自己寫分頁時,需要自己寫sql語句,並且進行分頁判斷之後才可以實現分頁 目前Mybatis提供了分頁外掛,使用起來非常簡便,適合於各類資料庫分頁,只需要在配置檔案中配置資料庫名即可,那麼mybatis的外掛作用在哪一環節呢?它主要作用在Executor執行器與ma

spring-boot 整合mybatis外掛PageHelper和Generator (番外)

分頁外掛PageHelper 新增maven依賴 根據上面地址中的說明,只需要新增如下依賴,並且可以不再mybatis的依賴 <!--分頁外掛--> <dependency> <groupId>com.github.pag

spring-boot 整合mybatis外掛PageHelper和Generator

原文地址:http://blog.csdn.net/zl18310999566/article/details/54097273 分頁外掛PageHelper 新增maven依賴 根據上面地址中的說明,只需要新增如下依賴,並且可以不再myba

Mybatis外掛pagehelper的簡單使用

對於使用Mybatis時,最頭痛的就是寫分頁,需要先寫一個查詢count的select語句,然後再寫一個真正分頁查詢的語句,當查詢條件多了之後,會發現真不想花雙倍的時間寫count和select,所以這個時候我們可以使用Mybatis的分頁外掛pagehelpe

Gradle構建SpringBoot+Mybatis整合外掛PageHelper

使用Gradle構建SpringBoot專案,使用Mybatis來持久化,嘗試整合PageHelper分頁外掛,依然順利都令到我吃驚,so easy! 首先,build.gradle中配置依賴 dependencies { compile gro