abel533 / MyBatis-Spring-Boot

Spring Boot集成MyBatis的基础项目
3.37k stars 1.59k forks source link

how can i integration spring boot mybatis with pagehelper #12

Closed chengbaobao630 closed 8 years ago

chengbaobao630 commented 8 years ago

when i use pagehelper and annotation Sqlprovider

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'providerTakesParameterObject' in 'class org.apache.ibatis.builder.annotation.ProviderSqlSource'

i find field providerTakesParameterObject in class PageProviderSqlSource ,but not in use

abel533 commented 8 years ago

Before mybatis 3.3.1, SqlProvider has providerTakesParameterObject.

After mybatis 3.4.0, SqlProvider remove providerTakesParameterObject, and add a new field named providerMethodArgumentNames.

try {
    //先针对3.3.1和之前版本做判断
    this.providerTakesParameterObject = (Boolean) metaObject.getValue("providerTakesParameterObject");
} catch (ReflectionException e) {
    //3.4.0+版本,解决#102 by Ian Lim
    providerMethodArgumentNames = (String[]) metaObject.getValue("providerMethodArgumentNames");
}

In PageSqlProviderSqlSource, use providerTakesParameterObject to recognition mybatis version, and run different createSqlSource method.

private SqlSource createSqlSource(Object parameterObject) {
    if(providerTakesParameterObject != null){
        return createSqlSource331(parameterObject);
    } else {
        return createSqlSource340(parameterObject);
    }
}
abel533 commented 8 years ago

what version of mybatis do you use?

chengbaobao630 commented 8 years ago

3.4.0

chengbaobao630 commented 8 years ago

i have fixed it after upgrade my pagehelper version to 4.1.5,thanks.