mybatis 报错:Cause: java.lang.NumberFormatException: For input string: “”


问题描述

我使用的mybatis版本是3.5.5。
使用mybatis动态SQL进行模糊查询,if条件判断时,报出数字格式错误。

 //Mapper.xml源代码<select id="selectByCondition" resultMap="brandResultMap">select *from tb_brandwherestatus = #{status}<if test="companyName != null and companyName != ' '">and company_name like #{companyName}</if><if test="brandName != null and brandName != ' '">and brand_name like #{brandName}</if></select>
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.NumberFormatException: For input string: "%华为%"
### Cause: java.lang.NumberFormatException: For input string: "%华为%"... moreat org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:39)at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:305)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:87)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)... 32 moreProcess finished with exit code -1

原因分析:

问题的原因在于mybiatis是基于OGNL语法,在解析单引号+单字符 ‘Y’ 的解析时会默认时char类型,单引号+多字符 ‘AA’ 或者双引号+单字符 “A” 解析为String类型。


解决方案:

把单引号和双引号的位置互换即可。

     <if test='companyName != null and companyName != " "'>and company_name like #{companyName}</if>

mybatis 报错:Cause: java.lang.NumberFormatException: For input string: ““相关推荐

  1. 访问swagger/Knife4j 接口文档报错:java.lang.NumberFormatException: For input string: ““

    目录 问题描述 解决过程 问题描述 报异常如下:java.lang.NumberFormatException: For input string: "" 虽然不影响使用,但是每次 ...

  2. 关于Swagger报错java.lang.NumberFormatException: For input string: 的总结

    关于Swagger报错java.lang.NumberFormatException: For input string: ""的总结 1 为什么会报错? 2 如何排错? 3 哪种 ...

  3. Mybatis报错: Error querying database. Cause: java.lang.NumberFormatException: For input string: “A“

    报错信息:Error querying database. Cause: java.lang.NumberFormatException: For input string: "A" ...

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

    Cause: java.lang.NumberFormatException: For input string 异常提示 异常来源 异常解决 异常提示 Error querying database ...

  5. swagger报错 java.lang.NumberFormatException: For input string: ““

    项目中集成Swagger,每次刷新页面,都给我报一个java.lang.NumberFormatException: For input string: ""的错误,真的是犯强迫症 ...

  6. 线上flink任务重启报错(Hadoop问题)java.lang.NumberFormatException: For input string: “30s“

    线上Flink任务重启时,提交任务失败,具体报错如下: 2021-12-31 18:09:19 java.lang.NumberFormatException: For input string: & ...

  7. 关于java.lang.NumberFormatException: For input string:${redis.maxIdle}的报错

    项目通用文件配置目录 reids配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...

  8. java.lang.NumberFormatException: For input string: F

    在通过myBatis执行sql时,报错: java.lang.NumberFormatException: For input string: "F" xml中sql内容为: &l ...

  9. Caused by: java.lang.NumberFormatException: For input string: “?2130969371“

    Caused by: java.lang.NumberFormatException: For input string: "?2130969371" 题记报错. 上结论:&quo ...

最新文章

  1. 个人博客开发-01-nodeJs项目搭建
  2. python大数据结课报告_2020知到大数据分析的PYTHON基础结课答案
  3. 基于Reddsion分布式的锁实现
  4. Pentest Box -windows平台的linux bash,集成了很多测试工具
  5. wider face data 在 faster rcnn 上的实践记录(caffe)
  6. 科技行业风投日趋谨慎:VR、机器学习和汽车值得关注
  7. 女人跳槽:最重要的是你的独立,你的快乐
  8. react router官方文档_阿里开源可插拔 React 跨端框架 UmiJS
  9. linux 系统调用_Linux系统调用初学者指南
  10. 结构变量的定义和引用
  11. DriverMessageBean配置详解
  12. sitecore系统教程之体验编辑器
  13. 软件加密狗破解思路和防破解的博弈之路
  14. python 怎么将数字转大写_python中如何将货币数字转化成汉字大写
  15. Arcgis进行人口密度计算
  16. 学生信息管理系统python面向对象_Python学员管理系统【面向对象实现】
  17. 用Verilog编写“数显LED的亮度控制电路”
  18. 开发常用镜像站 - 阿里云镜像站
  19. P1234 小A的口头禅题解
  20. TLV自定义通信协议的编码和解析

热门文章

  1. 2022年稀释制冷机全球市场规模达2.11亿美元,2028年有望出现突破点
  2. 基于php的网络投票在线投票系统
  3. 金蝶KIS K3提示当前使用的功能与其他用户有冲突的解决办法
  4. 液晶屏接口LVDS接口与MIPI DSI接口区别
  5. 大数据“拉网捕鼠” 博时基金马乐深圳受审
  6. 二维码图片转换成矩阵
  7. NanoPi M1 Plus OpenWRT挂载NFS rootfs
  8. Logstash [logstash.outputs.elasticsearch][main] retrying failed action with response code: 403
  9. Java基础入门(持续更新)
  10. 中科蓝讯蓝牙方案开发--调通话汇总