<if test="query.tenantId != null and query.tenantId != '' and query.tenantId != '0'">
                AND tenant_id = #{query.tenantId}
            </if>

当tenantId ="0"时判断条件为true 会加上这个查询条件。当吧判断条件写成

<if test="query.tenantId != null and query.tenantId != '' and query.tenantId != 0">
                AND tenant_id = #{query.tenantId}
            </if>

时判断条件为false 不会加上这个判断条件

Comment From: harawata

Hello @Woshizz ,

If the type of query.tenantId is String, you have to use double quotes. i.e.

<if test='name != null and name != "" and name != "0"'>

In OGNL, a character enclosed in single quotes (e.g. '0') is recognized as a char, so query.tenantId != '0' will always be true.


If this is not what you mean, please provide a test case or small demo project with assertions.