mybatis的条件判断

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容