mybatis 报错:Caused by: java.lang.NumberFormatException: For input string
mybatis的if标签之前总是使用是否为空,今天要用到字符串比较的时候遇到了困难,倒腾半天,才在一个论坛上找到解决方法。笔记一下,如下:
转自:https://code.google.com/p/mybatis/issues/detail?id=262
错误描述:
<select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment">
select *
from treatment
where TRUE
<if test="index == 'A'">
AND ensubject IS NOT NULL AND ensubject <> ''
</if>
</select>
当使用的index为A时,这段便抛出一个NumberFormatExeption的异常,但是如果index为一个数值比如1时就运行正常。
错误:
Caused by: java.lang.NumberFormatException: For input string: "A"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at org.apache.ibatis.ognl.OgnlOps.doubleValue(OgnlOps.java:)
at org.apache.ibatis.ognl.OgnlOps.compareWithConversion(OgnlOps.java:)
at org.apache.ibatis.ognl.OgnlOps.isEqual(OgnlOps.java:)
at org.apache.ibatis.ognl.OgnlOps.equal(OgnlOps.java:)
at org.apache.ibatis.ognl.ASTEq.getValueBody(ASTEq.java:)
at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:)
at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:)
at org.apache.ibatis.builder.xml.dynamic.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:)
at org.apache.ibatis.builder.xml.dynamic.IfSqlNode.apply(IfSqlNode.java:)
at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:)
at org.apache.ibatis.builder.xml.dynamic.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:)
解决方案:
1.改为:test="param eq 'A'.toString()"
2.原因是OGNL语法的问题:
这里 'A' 将被认为是 char 类型,但是 'AA' 或者 "A" 将被作为 String类型。
所以我们可以用转义:<if test="name == "A"">
3.或者将 <if test="index == 'A'"> 改为 <if test='index == "A"'>。
mybatis 报错:Caused by: java.lang.NumberFormatException: For input string的更多相关文章
- MyBatis报错:Caused by: java.lang.NumberFormatException: For input string: "XX"
<select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment"& ...
- Caused by: java.lang.NumberFormatException: For input string: "18446744073709551615"
问题:Caused by: java.lang.NumberFormatException: For input string: "18446744073709551615" 原因 ...
- 执行Hive时出现org.apache.hadoop.util.RunJar.main(RunJar.java:136) Caused by: java.lang.NumberFormatException: For input string: "1s"错误的解决办法(图文详解)
不多说,直接上干货 问题详情 [kfk@bigdata-pro01 apache-hive--bin]$ bin/hive Logging initialized -bin/conf/hive-log ...
- Caused by: java.lang.NumberFormatException: For input string: ""
1.错误描写叙述 java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatEx ...
- Caused by: java.lang.NumberFormatException: For input string: " 60"
原因 原原因:string转int 格式出错 解决:我的输入文件格式在根据“,”分割完之后多出了一个空格,我想要的是“60” 但是分割完之后是“ 60”所以导致格式转换不匹配.
- maven项目中使用redis集群报错: java.lang.NumberFormatException: For input string: "7006@17006"
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [redis.client ...
- Mybatis异常:java.lang.NumberFormatException: For input string: "S"
MyBatis异常日志如下: Caused by: java.lang.NumberFormatException: For input string: "S" at sun.mi ...
- java.lang.NumberFormatException: For input string: "${jdbc.maxActive}"
一.问题 使用SpringMVC和MyBatis整合,将jdbc配置隔离出来的时候出现下面的错误,百度了很久没有找到解决方法,回家谷歌下,就找到解决方法了,不得不说谷歌就是强大,不废话,下面是具体的错 ...
- org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NumberFormatException: For input string: "W%" ### Cause: java.lang.NumberFormatException: For input s
一个常见的myBatis xml文件中的引号错误: org.apache.ibatis.exceptions.PersistenceException: ### Error querying data ...
随机推荐
- 朝鲜RedStar_OS_3.0安装图解
前天exploit-db上出现了3个Local Exploit,都是来自朝鲜的RedStar 3.0的vul.网上也下到了镜像,按网上的方法测试了下,真的是 ————————————————————— ...
- Ubuntu14.04LTS安装记录(办公室联想台式机)
一.用UltraISO制作U盘启动器,被安装的电脑要设置成从U盘启动. 二.傻瓜式安装简体中文版 三.安装更新 sudo apt-get update sudo apt-get upgrade 四.安 ...
- Treap树
Treap树算是一种简单的优化策略,这名字大家也能猜到,树和堆的合体,其实原理比较简单,在树中维护一个"优先级“,”优先级“ 采用随机数的方法,但是”优先级“必须满足根堆的性质,当然是“大根 ...
- Spring MVC 问题列表:目录
学习SpringMVC时遇到不少问题,这里将其汇总. 1.怎么搭建SpringMVC 2.SpringMVC和Spring使用是配置到一个文件中还是两个配置文件 3.SpringMVC接受从前台请求 ...
- c语言的几个重要知识点
内存结构 这是核心中的核心,请仔细看完,充分理解,否则请不要看下一节内容. 每个程序一启动都有一个大小为4GB的内存,这个内存叫虚拟内存,是概念上的,真正能用到的,只是很小一部分,一般也就是在几百 ...
- 如何开启php报错
今天碰到一个很二的问题,安装了php网站之后,发现nginx一直无法解析到index.php文件,显示为空白,从后台的日志来看是500错误,但是同目录下的phpinfo.php却可以正常解析.想来应该 ...
- 怎么从sqlserver 数据库导出 insert 的数据语句
In SSMS in the Object Explorer, right click on the database right-click and pick "Tasks" a ...
- intel xdk 打ios的ipa包
1.打包 2.点击edit.下载csr文件,然后上传到苹果开发者网址,生成cer文件 上面两步搞完,把最后的按钮设置成"yes" 3.上传配置文件
- cocos2d-html5在cocos2d-x里面打包编译
main.cpp打开USE_WIN32_CONSOLE输出 #include "main.h" #include "AppDelegate.h" #includ ...
- 使用IIS6.0遇到问题后,常用的几种解决方法
1.检查 .Net Framework,是否安装完全,不确定的情况下使用:aspnet_regiis.exe -i 或者 aspnet_regiis.exe -r 2.检查 IIS 6.0 其它相关配 ...