在使用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">