mybatis的xml中if判断的test条件为字符串中包含另一个字符串
<foreach collection="list" item="item" index="index" separator="AND" open="(" close=")">
<choose>
<when test='itemame.contains("select") or itemame.contains("checkbox") or itemame.contains("date")'>
<if test='itemame.contains("select") or itemame.contains("checkbox")'>
find_in_set(#{item.value},base.${itemame})
</if>
</when>
<otherwise>
base.${itemame} = #{item.value}
</otherwise>
</choose>
</foreach>
mybatis xml文件中用 if 标签判断字符串是否相等
<if test="delFlag == '2'.toString()">
a.del_flag = #{delFlag}
</if>
<if test=' delFlag == "2" '>
a.del_flag = #{delFlag}
</if>
以上两种 ,都可以实现在 myBatis xml 文件中,实现对字符串的判断。
<if test=" delFlag == '2' ">
a.del_flag = #{delFlag}
</if>
使用上面示例中 "delFlag ==‘2’ " , Mybatis会将 “2” 解析为字符(java 强类型语言, ‘2’ char 类型 ),而非字符串,不能做到判断的效果。 要在Mybatis中判断字符串是否相等,请使用 方法一 或 方法二。
更多推荐
mybatis的xml中if判断的test条件为字符串中包含另一个字符串
发布评论