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