mybatis的条件判断
2018-12-13 本文已影响0人
平面小狮子
一、mybatis if 条件判断为空处理
<if test="userId != null and userId != '' ">
and u.userId = #{userId}
</if>
二、mybatis if 条件对比字符串是否相等
<if test="userId != null and userId != '' ">
<if test='userId == "0" '>
and u.userId = #{userId}
</if>
</if>
注: <if test='userId == "0" '> 值必须用 " " ,外层必须是 ' '
三、mybatis if条件判断写法
<choose>
<when test="userId != null and userId != '' ">
and u.userId = #{userId}
</when>
<otherwise>
and u.userId like #{userId}||'%'
</otherwise>
</choose>