欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

MyBatis sql中test如何判断Boolean

时间:2022-06-02 10:04:15|栏目:JAVA代码|点击:

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>

上一篇:Java中的Unsafe在安全领域的使用总结和复现(实例详解)

栏    目:JAVA代码

下一篇:java实现输出任意整数的每一位

本文标题:MyBatis sql中test如何判断Boolean

本文地址:http://www.codeinn.net/misctech/203515.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有