一、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>