pagehelper 插件应用报错:ConversionNotSupportedException: Failed to convert property value of type ‘java.la
来源:互联网 发布:网络奇葩歌词找歌 编辑:程序博客网 时间:2024/06/05 19:57
Mybatis物理分页插件PageHelper 5.0
昨天在Maven管理的项目中集成PageHelper的时候总是没有成功。我采用的是Spring的集成方式。
因为我使用的是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 + "'"); } }}
这里我发现plugin是Interceptor,没办法,只能在github上找最新的PageHelper的文档了。
突然发现这儿坑还挺多的。下面我就把PageHelper 5.0与以前版本不一样的地方给贴出来。
- 使用 QueryInterceptor 规范 处理分页逻辑 新的分页插件拦截器为
com.github.pagehelper.PageInterceptor 新的 PageHelper 是一个特殊的 Dialect - 实现类,以更友好的方式实现了以前的功能 新的分页插件仅有 dialect 一个参数,默认的 dialect 实现类为 PageHelper
- PageHelper 仍然支持以前提供的参数,在最新的使用文档中已经全部更新 PageHelper 的 helperDialect 参数和以前的 dialect 功能一样,具体可以看文档的参数说明
- 增加了基于纯 RowBounds 和 PageRowBounds 的分页实现,在com.github.pagehelper.dialect.rowbounds 包中,这是用于作为 dialect 参数示例的实现,后面会补充更详细的文档 去掉了不适合出现在分页插件中的 orderby功能,以后会提供单独的排序插件
- 去掉了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>
还有一个小坑需要注意的是,在5.0中使用了helperDialect代替了原来的dialect属性。
- pagehelper 插件应用报错:ConversionNotSupportedException: Failed to convert property value of type ‘java.la
- org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.la
- spring mvc 数据绑定报错 Failed to convert property value of type 'java.lang.String' to required type 'int'
- Failed to convert property value of type [java.lang.String] to required type [boolean] for property
- Failed to convert property value of type 'java.lang.String' to required type 'int' for property
- Failed to convert property value of type 'java.util.Properties' to required type 'org.springframewor
- springmvc-- Failed to convert property value of type 'java.lang.String' to required type
- Failed to convert property value of type [java.lang.String] to required type [int]
- mybatis 5.0 报错 Cannot convert value of type ‘com.github.pagehelper.PageHelper’ to required type ‘org
- Failed to convert property value of type 'java.util.LinkedHashMap' to required
- 表单提交时候"Failed to convert property value of type [java.lang.String] to
- Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
- Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
- Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for pr
- 关于springMVC中:Failed to convert property value of type 'java.lang.String' to required type 'java.util
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- Failed to convert property value of type [$Proxy13] to required type
- spring 事务异常Failed to convert property value of type [$Proxy12] to required type
- 解题报告:Codeforces Round #421 (Div. 2) A-E
- NIO 入门
- uCOS-II中的任务切换机制
- python自然语言处理 第二章(上)
- FFMpeg无损合并视频的多种方法
- pagehelper 插件应用报错:ConversionNotSupportedException: Failed to convert property value of type ‘java.la
- html的属性操作01
- 《奥威Power-BI自定义计算的奥妙---工艺线产品合格率分析》精彩回顾
- 实用的网络模型
- GridView的最后固定显示一个增加图片,点击图片动态增加内容item
- Dubbo分布式架构实战--FastDFS分布式文件系统的安装与使用(单节点)
- Linux/CentOS 升级C基本运行库CLIBC的注意事项(当想解决GLIBC_2.x找不到的编译问题)
- Python书籍推荐
- .NET 针对465加密端口 加密协议SSL(Implicit SSL)进行的邮件发送