mybatis動態SQL. if標簽的test的參數為0時直接跳出if的問題


在使用mybatis做動態SQL查詢的時候, 如果參數的值為0, 則不會執行對應if標簽內的語句

<if test="healthQuery.healthStatus != null and healthQuery.healthStatus != ''">
    <if test="healthQuery.healthStatus == 0">
        AND sehr.health_rate between 80 and 100
    </if>
    <if test="healthQuery.healthStatus == 1">
        AND sehr.health_rate between 60 and 80
    </if>
    <if test="healthQuery.healthStatus == 2">
        AND sehr.health_rate between 0 and 60
    </if>
</if>

解決辦法

在判斷參數時, 去掉判斷其是否是空字符串的條件, mybatis過濾空字符串的時候也會把0值過濾掉

<if test="healthQuery.healthStatus != null and healthQuery.healthStatus != ''">
<if test="healthQuery.healthStatus != null">


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM