pagehelper调用mybatis报错java.lang.NoSuchMethodError:org.apache.ibatis.reflection.MetaObject.forObject

最近在升新的基础框架到 spring cloud,启动时 pagehelper 报错,如下:

java.lang.NoSuchMethodError:org.apache.ibatis.reflection.MetaObject.forObject(Ljava/lang/Object;Lorg/apache/ibatis/reflection/factory/ObjectFactory;Lorg/apache/ibatis/reflection/wrapper/ObjectWrapperFactory;)Lorg/apache/ibatis/reflection/MetaObject;

       atcom.github.pagehelper.SqlUtil.forObject(SqlUtil.java:78)

       atcom.github.pagehelper.SqlUtil.getsqlSource(SqlUtil.java:521)

       atcom.github.pagehelper.SqlUtil.getMappedStatement(SqlUtil.java:444)

       atcom.github.pagehelper.SqlUtil.processCountMappedStatement(SqlUtil.java:143)

       atcom.github.pagehelper.PageHelper.intercept(PageHelper.java:140)

       atorg.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
经查是 pagehelper 版本太高,自动引入的是 5.x 的,将为 4.1.8 之后,问题解决。

pagehelper 的几个要点:

1、pagehelper 真正改写 sql 是在最后 getBoundSql 的时候,而不是提前注入值。

 

2、采用的是 jsqlparser 解析器,它比 druid sql 弱得多,不过因为是最简单的解析,问题不是很大。

3、分页的执行是串行的,可以考虑并行。