美文网首页
mybatis的条件判断

mybatis的条件判断

作者: 平面小狮子 | 来源:发表于2018-12-13 16:56 被阅读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>

相关文章

网友评论

      本文标题:mybatis的条件判断

      本文链接:https://www.haomeiwen.com/subject/csebhqtx.html