在通过myBatis执行sql时,报错: java.lang.NumberFormatException: For input string: "F"

xml中sql内容为:

                    <if test="myKey == 'P' ">
and `Field1` = #{fieldname}
</if>

其中 fieldname的值为 F, 没明白会报 NumberFormatException, 明明是字符型,后一步步调试代码到:

\.m2\repository\org\mybatis\mybatis\3.5.2\mybatis-3.5.2.jar!\org\apache\ibatis\ognl\ASTNotEq.class

报错的代码为(OgnlOps.equal):

    protected Object getValueBody(OgnlContext context, Object source) throws OgnlException {
Object v1 = this._children[0].getValue(context, source);
Object v2 = this._children[1].getValue(context, source);
return OgnlOps.equal(v1, v2) ? Boolean.FALSE : Boolean.TRUE;
}

v1,v2值分别为下图:

v2的值成了P,得到v2的类型为:

没明白,后边试着把 <if test="myKey == 'P' "> 调整为:  <if test="myKey == 'PP' "> 多加了一个P

这时v2的类型就为String了,估计MyBatis如果发现为单字符,都统一处理为了 Character, 试着调整为: <if test="myKey == "P" "> 单引号改为双引号(或加转义符),都不行

试着转换单双引号为(test里外包的将双引号改为单引号, P字符调整为双引号):

                    <if test='myKey == "P" '>
and `Field1` = #{fieldname}
</if>

再试,功能正常

java.lang.NumberFormatException: For input string: "F"的更多相关文章

  1. Mybatis异常:java.lang.NumberFormatException: For input string: "S"

    MyBatis异常日志如下: Caused by: java.lang.NumberFormatException: For input string: "S" at sun.mi ...

  2. java.lang.NumberFormatException: For input string: "1608020001 " 错误

    错误: java.lang.NumberFormatException: For input string: "1608020001 "    at java.lang.Numbe ...

  3. java.lang.NumberFormatException: For input string: "Y"

    nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  ...

  4. mybatis 报错:Caused by: java.lang.NumberFormatException: For input string

    mybatis的if标签之前总是使用是否为空,今天要用到字符串比较的时候遇到了困难,倒腾半天,才在一个论坛上找到解决方法.笔记一下,如下: 转自:https://code.google.com/p/m ...

  5. java.lang.NumberFormatException: For input string:"filesId"

    做项目时候,页面获取出现了这个问题.找了好久一直以为是我字段或者是数据库字段问题导致引起的. 最后才发现是 struts2中jsp我写错了一个参数,一直导致报错.后来改了就好了. 当大家遇到这个问题的 ...

  6. 解决java.lang.NumberFormatException: For input string: "id"

    今天,项目突然报"java.lang.NumberFormatException:For input string:"id"",项目框架是spring,spri ...

  7. MyBatis报错:Caused by: java.lang.NumberFormatException: For input string: "XX"

    <select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment"& ...

  8. Caused by: java.lang.NumberFormatException: For input string: "18446744073709551615"

    问题:Caused by: java.lang.NumberFormatException: For input string: "18446744073709551615" 原因 ...

  9. Redis集群环境使用的是redis4.0.x的版本,在用java客户端jedisCluster启动集群做数据处理时报java.lang.NumberFormatException: For input string: "7003@17003"问题解决

    java.lang.NumberFormatException: For input string: "7003@17003" at java.lang.NumberFormatE ...

随机推荐

  1. JQuery 实现PPT效果,点跳目标页及翻页(待改进)

    实现PPT效果 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...

  2. ubuntu14 安装Express及简单应用

    参考资料 [1] 基于Express的Hello World实例 Express 是一个基于 Node.js 平台的极简.灵活的 web 应用开发框架. 1. 环境 工具名 版本 nodejs v11 ...

  3. 在 aws emr 上,将 hbase table A 的数据,对 key 做 hash,写到另外一张 table B

    先 scan 原表,然后 bulkload 到新表. 采坑纪录1. bulkload 产生 hfile 前,需要先对 hash(key) 做 repartition,在 shuffle 的 read ...

  4. SSM(Spring-SpringMvc-Mybatis)练习

    1.总结 https://pan.baidu.com/s/1kXlCf4r  密码:hv6v 2.代码 https://pan.baidu.com/s/1pNgKph5  密码:6rcm 3.资料 h ...

  5. 洛谷 P2891 [USACO07OPEN]吃饭Dining

    裸的最大流. #include <cstdio> #include <cstring> #include <queue> const int MAXN = 4e3 ...

  6. Python作业篇 day02

    作业 知识点回顾: 1.变量名的规范 2.简述 ascii unicode utf-8 的关系 3.简述 位与字节的关系 4.‘我是帅哥’  在utf-8编码用几个字节  ,在gbk用几个字节 逻辑运 ...

  7. 【剑指Offer面试编程题】题目1510:替换空格--九度OJ

    题目描述: 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 输入: 每个 ...

  8. 远程服务器使用tensorboard

    1 .由于服务器上tensorboard使用的端口是6006,因此,连接ssh时,将服务器的6006端口重定向到自己机器上的16006端口: ssh -L 16006:127.0.0.1:6006 u ...

  9. JS - 数组转字符串

        var arr =['h','e','l','l','o']     var s = arr.join("");       console.log(s); 

  10. Percona-Toolkit 之 pt-kill 用法

    生产环境中我们时常遇到这样的情况,数据库性能恶劣,需要马上杀掉部分会话,不然数据库就夯死.我们可以先找show processlist的输出来杀会话,但是比较麻烦.pt-kill为我们解决了杀会话问题 ...