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参数。如下:
以上就是记录自己的分页插件的排错过程,以便后来人方便查阅~
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分页插件
- Mybatis常用分页插件实现快速分页处理技巧
- 使用mybatis-generator添加自定义分页插件时提示无法实例化插件类
- 使用mybatis-generator添加自定义分页插件时提示无法实例化插件类
- 使用mybatis-generator添加自定义分页插件时提示无法实例化插件类
- mybatis常用分页插件,快速分页处理
- maven+mybatis+mybatis-generator+sql server 2005自动生成代码,加上自定义分页插件和批量插入更新插件
- mybatis常用分页插件,快速分页处理
- MyBatis自定义分页插件
- 在spring中配置mybatis 中自定义的拦截器插件
- Mybatis 数据库物理分页插件 PageHelper
- Mybatis的插件 PageHelper 分页查询使用方法
- php中自定义分页处理类
- mybatis结合bootstrap分页插件的使用
- (转)基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
- Mybatis分页插件更新
- Mybatis分页插件更新
- vue中的自定义分页插件组件的示例
- Mybatis分页插件PageHelper
- Mybatis分页插件-pagehelper