怎么使用mybatis 动态where 条件
相信很多人都知道 mybatis 动态where条件 是怎么写的 ,只需要这样
<where>
<if >
and id = #{id}
</if>
</where>
但是 如果在 where 条件有限制的情况下怎么使用呢 ,也是很简单的,上代码
<if test = "id!= null and id != ''">
id = #{id}
</if>
如果在需要判断 id 为具体是什么值 的情况下 我们需要特别加上.ToString() , 代码如下
<if test = "id!= null and id != ''">
<if test = "id == 'Y'.toString()">
id = #{id}
</if>
<if test = "id == 'N'.toString()">
id != 'Y'
</if>
</if>
注意一定要加上toString() 方法 否则 会报错 NumberFormatException