<foreach collection="accurateSearchMap" index="key" item="item">
<if test="key == 'gcc.sex' and item != '3' and item!='' and item!=null">
and ${key} = #{item}
</if>
<if test="key == 'gcc.classes' and item != '3' and item!='' and item!=null">
and ${key} = #{item}
</if>
<if test="key == 'gcc.add_target' and item != '2' and item!='' and item!=null">
and ${key} = #{item}
</if>
<if test="key == 'gcc.custype' and item != '3' and item!='' and item!=null">
and ${key} = #{item}
</if>
<if test="item!='' and item!=null and key != 'gcc.sex' and key != 'gcc.classes' and key != 'gcc.add_target' and key != 'gcc.custype'">
and ${key} = #{item}
</if>
</foreach>
因为accurateSearchMap是Map<String, Object>类型的,所以键对应的值是Object类型的,而对象间用==或!=比较的是地址引用,所以在值为Object类型的情况下以上代码是有问题的。
解决办法是:在值item后加上toString方法的调用,'1'后面也要加toString方法的调用
分享到:
相关推荐
本文将详细讨论在MyBatis映射文件中,`if`标签判断字符串相等的两种方法。 ### 方法一:使用OGNL表达式 MyBatis的`if`标签内支持OGNL(Object-Graph Navigation Language)表达式,这是一种强大的表达式语言,用于...
在另一方法`getListByStartDateAndEndDate`中,`<if>`标签用于判断`startDate`和`endDate`两个参数是否不相等。如果不相等,`<if>`标签内的内容(即`date between #{startDate} and #{endDate}`)将被添加到SQL语句...
- `<isNotEqual>`:用于判断两个值是否不相等,如果不相等则执行相应的SQL语句。 - `<isGreaterThan>`:用于判断一个值是否大于另一个值,如果是则执行相应的SQL语句。 - `<isGreaterEqual>`:用于判断一个值是否...
- `if-else if`语句适合于区间或范围判断,而`switch`语句更适合于固定值的选择。 #### 28. 编辑器快捷键 - **Ctrl+Shift+O**: 自动导入未使用的类或接口,这对于清理冗余代码、提高代码整洁度非常有帮助。 #### ...
3. **互异性**:如果两个对象不相等,则它们的哈希值最好不同,以减少哈希冲突。 #### 6. `==`在判断对象时的依据 - **`==`运算符**:在比较对象时,比较的是它们在内存中的地址。 #### 7. `final`关键字的作用 ...
字符串替换问题** ```java import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { String input = ...