您的位置:首页 > 其它

Mybatis自定义分页插件后报错处理

2017-05-20 11:21 1076 查看
前端时间,模仿pageHelper作者的Mybatis分页插件,自己修改并优化了一下,放在项目里运行后,却报错,报错如下

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error opening session. Cause: org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(java.sql.Connection)
### Cause: org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(java.sql.Connection)
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100)
其实仔细看报错提示,追到源码里看一下就知道原因了,因为用了比较新或者是最新的MyBatis jar包,而我的拦截器代码又是比较老的写法。在MyBatis新的jar包中,StatementHandler中的prepare方法有两个参数,如下:Statement prepare(Connection connection, Integer transactionTimeout),而我的拦截器代码里面却只有一个参数,所以就导致获取不到。解决方法便出来了,应该在分页拦截器的规则里面再追加一个Integer.class参数。如下:

@Intercepts
({
@Signature
(type=StatementHandler.
class
,method=
"prepare"
,args={Connection.
class
, Integer.
class
 
})})


以上就是记录自己的分页插件的排错过程,以便后来人方便查阅~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis 插件 分页 优化