MyBatis sql中test如何判断Boolean
作者:caox_nazi
这篇文章主要介绍了MyBatis sql中test如何判断Boolean,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
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>以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
