Mybatis中if 条件传入 0 作比较 的问题

Mybatis xml 中 用 <if> 判断传入的参数 当参数类型为数字 0  时, if 判断失效:

<if test = "reviewStatus != null and reviewStatus !='' ">
    <if test="reviewStatus == 0">
       having 0 = all
       (select tk.review_status from rp_review_task tk where
            <if test = "batchId != null and batchId != '' ">
                 tk.batch_id = #{batchId}
            </if>
        and tk.subject_id = task.subject_id)
    </if>
</if>

像 上面的 “reviewStatus” 同 “0” 作比较的时候,如果传入的参数是 0 ,<if> 条件 是成立的,但是打印的 sql 却没有拼接 <if> 中的sql。原因是:外层的<if> 条件 中 “ reviewStatus != '' ” 这个条件惹的祸,把它去掉就可以了。(遇到的坑,百度解决了)


版权声明:本文为Dzq_Boyka原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。