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