java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > mybatis if判断字符串

Mybatis3 if判断字符串变态写法

投稿:mrr

这篇文章主要介绍了Mybatis3 if判断字符串变态的写法,非常不错,具有参考借鉴价值,需要的朋友参考下

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

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

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

您可能感兴趣的文章:
阅读全文