首页 > 开发 > Java > 正文

Mybatis3 if判断字符串变态写法

2024-07-13 10:02:47
字体:
来源:转载
供稿:网友

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

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

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

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

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

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

补充:Mybatis3 判断字符串

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

mapper内如下:

<choose> <when test="regOrSign != null and regOrSign == 'R' "> ORDER BY a.registrationDate DESC </when> <otherwise> ORDER BY a.signDate DESC </otherwise></choose>

报错:

### 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"test="regOrSign != null and regOrSign == 'R' "-> test='regOrSign != null and regOrSign == "R" '

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

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


注:相关教程知识阅读请移步到JAVA教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表