MyBatissql test判断Boolean
caox_nazi 人气:0mybatis 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>
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
加载全部内容