信息发布→ 登录 注册 退出

MyBatis sql中test如何判断Boolean

发布时间:2026-01-11

点击量:
目录
  • mybatis sql中test判断Boolean
    • 三种方式
  • if标签判断boolean类型的写法
    • 例子方法
    • 在入参flag不为空的情况下直接判断

mybatis sql中test判断Boolean

三种方式

<select id="queryAddress" resultType="com.caox.model.Address">
        select id, address, remark
        from address where
        1=1
        <if test="flag==true">
         and  address = #{address}
        </if>
    </select>
<update id="updateHaveNewComment">
        <choose>
            <when test="flag==true">
                UPDATE epc_subject_center s
                SET s.have_new_comment=1
                WHERE s.id=#{id}
            </when>
            <otherwise>
                UPDATE epc_subject_center s
                SET s.have_new_comment=0
                WHERE s.id=#{id}
            </otherwise>
        </choose>
    </update>
<update id="updateHaveNewComment">
        <choose>
            <when test="flag">
                UPDATE epc_subject_center s
                SET s.have_new_comment=1
                WHERE s.id=#{id}
            </when>
            <otherwise>
                UPDATE epc_subject_center s
                SET s.have_new_comment=0
                WHERE s.id=#{id}
            </otherwise>
        </choose>
    </update>

if标签判断boolean类型的写法

例子方法

在入参flag不为空的情况下直接判断

<if test="flag">
       AND order_status IN(1, 2, 3)
</if>
<if test="!flag">
       AND order_status IN(4, 5, 6)
</if>
<<choose>
     <when test="!flag">
             AND order_status  IN (4, 5, 6)
     </when>
     <otherwise>
             AND order_status  IN (1, 2, 3)
     </otherwise>
</choose>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!