在mybatis的Mapper.xml文件中,如果需要在<if>标签中判断字符串是否相等,是不能使用:
<if test="str == '0'"></if>
这种方式的。
解决方式有两种:
- 使用toString()方法:
<if test="str == '0'.toString() "></if>
- 使用单引号嵌套双引号的方法:
<if test='str == "0" '></if>
本文介绍在MyBatis的Mapper.xml文件中如何正确进行字符串相等判断。文中指出直接使用等于号的方式不可行,并提供了两种解决方案:一是通过toString()方法转换;二是使用单引号嵌套双引号的方法。
在mybatis的Mapper.xml文件中,如果需要在<if>标签中判断字符串是否相等,是不能使用:
<if test="str == '0'"></if>
这种方式的。
解决方式有两种:
<if test="str == '0'.toString() "></if>
<if test='str == "0" '></if>

被折叠的 条评论
为什么被折叠?