Mybatis:字符比较导致的报错 MyBatisSystemException PersistenceException NumberFormatException

导读:本篇文章讲解 Mybatis:字符比较导致的报错 MyBatisSystemException PersistenceException NumberFormatException,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

报错

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: ">"
### Cause: java.lang.NumberFormatException: For input string: ">"
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)

Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: ">"
### Cause: java.lang.NumberFormatException: For input string: ">"
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

Caused by: java.lang.NumberFormatException: For input string: ">"
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
        at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
        at java.lang.Double.parseDouble(Double.java:538)
        at org.apache.ibatis.ognl.OgnlOps.doubleValue(OgnlOps.java:253)
        at org.apache.ibatis.ognl.OgnlOps.compareWithConversion(OgnlOps.java:104)
        at org.apache.ibatis.ognl.OgnlOps.isEqual(OgnlOps.java:153)
        at org.apache.ibatis.ognl.OgnlOps.equal(OgnlOps.java:814)
        at org.apache.ibatis.ognl.ASTEq.getValueBody(ASTEq.java:52)
        at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
        at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:586)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:550)
        at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:46)
        at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)
        at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:34)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
        at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:35)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
        at org.apache.ibatis.scripting.xmltags.ForEachSqlNode.apply(ForEachSqlNode.java:79)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
        at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:35)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
        at java.util.ArrayList.forEach(ArrayList.java:1259)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
        at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:39)
        at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:305)
        at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:69)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
        at com.sun.proxy.$Proxy137.query(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor214.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
        at com.github.yulichang.interceptor.MPJInterceptor.intercept(MPJInterceptor.java:83)
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
        at com.sun.proxy.$Proxy137.query(Unknown Source)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)
        ... 105 common frames omitted

报错原因

根据上面第三段报错,会发现是类型转换报错

往上追代码,会发现:

mybatis的xml 标签表达式中,会把入参只有一个字符的尝试转成数字

修改方式

表达式的单双引号互换

XML中的SQL-修改前

<if test="s.condition=='='">
                        ${screenRelation} share.create_time between '${s.value} 00:00:00' and '${s.value} 23:59:59'
                    </if>
                    <if test="s.condition!='='">
                        ${screenRelation} share.create_time <![CDATA[${s.condition}]]> #{s.value}
                    </if>

XML中的SQL-修改后

<if test='s.condition=="="'>
                        ${screenRelation} share.create_time between '${s.value} 00:00:00' and '${s.value} 23:59:59'
                    </if>
                    <if test='s.condition!="="'>
                        ${screenRelation} share.create_time <![CDATA[${s.condition}]]> #{s.value}
                    </if>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/93678.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!