mybatis if判断字符串 Mybatis3 if判断字符串变态写法
人气:0想了解Mybatis3 if判断字符串变态写法的相关内容吗,在本文为您仔细讲解mybatis if判断字符串的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:mybatis,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="regOrSign != null and regOrSign == 'R' " -> test='regOrSign != null and regOrSign == "R" '
改成这样就可以了,这个问题同样适用if标签
以上所述是小编给大家介绍的Mybatis3 if判断字符串变态写法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
加载全部内容