在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

Mybatis3 if判断字符串变态写法

2017-3-7 12:50| 发布者: zhangjf| 查看: 1153| 评论: 0

摘要: mybatis我们常用的判空操作,出现了常见问题: 错误写法:if test=”status == ‘Y'” 结果:抛异常NumberFormatException异常!提示内容非常少,看不出问题在哪里! 正确写法:if test='status == “y”' 还可以 ...

mybatis我们常用的判空操作,出现了常见问题:

错误写法:if test=”status == ‘Y'”

结果:抛异常NumberFormatException异常!提示内容非常少,看不出问题在哪里!

正确写法:if test='status == “y”'

还可以这样写:if test=”status == ‘y'.toString()”

或者可以这样写 if test ='status==”Y”'

补充:Mybatis3 判断字符串

在使用Mybatis3过程中发现一个奇怪的问题,判断字符串必须要用指定的格式

mapper内如下:

  1. <choose>
  2. <when test="regOrSign != null and regOrSign == 'R' ">
  3. ORDER BY a.registrationDate DESC
  4. </when>
  5. <otherwise>
  6. ORDER BY a.signDate DESC
  7. </otherwise>
  8. </choose>
复制代码

报错:

  1. ### Error querying database. Cause: java.lang.NumberFormatException: For input string: "R" ### Cause: java.lang.NumberFormatException: For input string: "R"] with root cause java.lang.NumberFormatException: For input string: "R"
  2. test="regOrSign != null and regOrSign == 'R' "
  3. -> test='regOrSign != null and regOrSign == "R" '
复制代码

改成这样就可以了,这个问题同样适用if标签

以上所述是小编给大家介绍的Mybatis3 if判断字符串变态写法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对程序员之家网站的支持!

最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-5-4 02:09

Copyright 2015-2025 djqfx

返回顶部