MyBatis sql中test如何判斷Boolean
更新時間:2022年01月14日 12:05:08 作者: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類型的寫法
例子方法

在入?yún)lag不為空的情況下直接判斷
<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>以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Springboot2.x 使用 Log4j2 異步打印日志的實現(xiàn)
這篇文章主要介紹了Springboot2.x 使用 Log4j2 異步打印日志的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
idea中提示Class 'xxx' is never us
這篇文章主要介紹了idea中提示Class 'xxx' is never used的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01
解決Java變異出現(xiàn)錯誤No enclosing instance of type XXX is accessible
這牌你文章主要給大家分享解決Java變異出現(xiàn)錯誤,具體的饑餓絕方案請看下面文章的內(nèi)容,需要的朋友可以參考一下,希望能幫助到你2021-09-09
關(guān)于Java鎖性能提高(鎖升級)機制的總結(jié)
這篇文章主要介紹了關(guān)于Java鎖性能提高(鎖升級)機制的總結(jié),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-05-05

