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">
原文地址:https://www.cnblogs.com/qds1401744017/p/13600048.html