Mybatis异常:java.lang.NumberFormatException: For input string: "S"
MyBatis异常日志如下:
Caused by: java.lang.NumberFormatException: For input string: "S"
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:243)
at org.apache.ibatis.ognl.OgnlOps.compareWithConversion(OgnlOps.java:100)
at org.apache.ibatis.ognl.OgnlOps.isEqual(OgnlOps.java:143)
at org.apache.ibatis.ognl.OgnlOps.equal(OgnlOps.java:802)
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:470)
at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:434)
at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:44)
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.apply(MixedSqlNode.java:33)
at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:35)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)
at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:55)
at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)
at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:41)
at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
at com.shengpay.hpsplus.db.interceptor.SlowSqlInterceptor.intercept(SlowSqlInterceptor.java:47)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy185.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
... 45 more
将mybatis的日志级别调整为debug仍然没有看到sql打印,因此排除sql异常,可能是sql预处理报错了。
<logger name="org.apache.ibatis">
<level value="debug" />
</logger>
仔细排查异常,原来是如下地方有问题:
<if test="dataType == 'F'">
and INSERT_TIME > sysdate - 1
</if>
错误分析:
1、test=“datatype == ‘F’ ” 使用的OGNL表达式,而datatype的类型定义如下:
<result column="DATA_TYPE" jdbcType="CHAR" property="dataType" />
该地方想表达的含义是:如果datatype == 字符'F'的条件成立
但是呢,DB中字段的定义是char,可是,在我们使用(test=“datatype == ‘F’ ”)这个ognl表达式做判断的时候,使用的是datatype,而datatype是如何定义的呢?
private String dataType;
问题找到了:
(test=“datatype == ‘F’ ”) 这个表达式,使用了datatype 这个字符串和'F'这个字符做比较,字符和字符串比较,mybatis会做数据类型的统一转换,好了出问题了!!!
解决方案,吧'F'当做字符串对待,用双引号标示:"F"
<if test='dataType == "F"'>
and INSERT_TIME > sysdate - 1
</if>
搞定!!!
Mybatis异常:java.lang.NumberFormatException: For input string: "S"的更多相关文章
- Swagger2异常 java.lang.NumberFormatException: For input string: ""
问题在访问swagger首页时报错: java.lang.NumberFormatException: For input string: "" at java.lang.Numb ...
- mybatis 报错:Caused by: java.lang.NumberFormatException: For input string
mybatis的if标签之前总是使用是否为空,今天要用到字符串比较的时候遇到了困难,倒腾半天,才在一个论坛上找到解决方法.笔记一下,如下: 转自:https://code.google.com/p/m ...
- MyBatis报错:Caused by: java.lang.NumberFormatException: For input string: "XX"
<select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment"& ...
- 解决测试redis集群时报"java.lang.NumberFormatException: For input string: "7003@17003..7002@17002"等异常
一.前言 关于redis5.0的集群模式下,通过客户端测试代码调试报"Exception in thread "main" java.lang.NumberFormatE ...
- java.lang.NumberFormatException: For input string: "title"异常
java.lang.NumberFormatException: For input string: "title" at java.lang.NumberFormatExcept ...
- java.lang.NumberFormatException: For input string: "Y"
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. ...
- java.lang.NumberFormatException: For input string: "${jdbc.maxActive}"
一.问题 使用SpringMVC和MyBatis整合,将jdbc配置隔离出来的时候出现下面的错误,百度了很久没有找到解决方法,回家谷歌下,就找到解决方法了,不得不说谷歌就是强大,不废话,下面是具体的错 ...
- Cause: java.lang.NumberFormatException: For input string: "D"
异常:Cause: java.lang.NumberFormatException: For input string: "D" 问题回显: 原因分析:'D'只有1位,被认为是ch ...
- 解决java.lang.NumberFormatException: For input string: "id"
今天,项目突然报"java.lang.NumberFormatException:For input string:"id"",项目框架是spring,spri ...
随机推荐
- js字符串与数字之间的比较
//1.纯数字之间比较 console.log(1<3);//true //2.纯字符串比较,先转成ASCII码,按位依次比较 console.log("1"<&quo ...
- Django相关的MTV
- js 中callback函数的定义和使用
这是js里的解释了,其他语言的算我没说. 字面上理解下来就是,回调就是一个函数的调用过程.那么就从理解这个调用过程开始吧.函数a有一个参数,这个参数是个函数b,当函数a执行完以后执行函数b.那么这个过 ...
- If you are tired...
如果你累了 1. 深呼吸 放松身体,深呼吸五分钟. 2. 听音乐 静静地听几首歌放松一下就好了,比如王豪学长推荐的追梦赤子心,骄傲的少年. 3. 冥想 放松身体,处于冥想状态. 4. 干洗脸.鸣天鼓. ...
- 牛客网Java刷题知识点之代码块(局部代码快、构造代码块、静态代码块)
不多说,直接上干货! 代码块包括局部代码快.构造代码块.静态代码块. 代码块,就是一段独立的代码空间. 1.局部代码快 对局部变量的生命周期进行控制. 2.构造代码块 对所有对象进行初始化. 3.静态 ...
- verilog if语句
a.基本形式 1) if(表达式) 语句1: 2)if(表达式) 语句1: else 语句1 3) if(表达式1) 语句1: else if(表达式2) 语句2: else if(表达式3) ...
- javascript 数组方法拼接html标签
var htmls = new Array(); htmls.push("<tr class='otherinfotr'>");htmls.push("< ...
- Java基础入门 - 关键字及其分类和说明
类别 关键字 说明 访问控制 private 私有的 protected 受保护的 public 公共的 类.方法和变量修饰符 abstract 声明抽象 class 类 extends 扩充,继承 ...
- 从零开始的全栈工程师——js篇2.21(事件对象 arguments 阻止事件默认行为兼容 事件委托 事件源对象)
一.事件对象 1.常用的事件2.每个元素身上的事件都是天生存在的 不需要我们去定义 只需要我们给这个事件绑定一个方法 当事件触发的时候就会执行这个方法 3.事件绑定的写法 ①div.onclick=f ...
- DIV内数据删除操作
对于数据操作,前端提供静态方法,交给后台去操作 此处记录一下,待优化,不过精华都在里面了 静态页面: 鼠标移上显示: html代码 css代码 js代码