mybatis踩坑笔记

283 阅读1分钟

动态sql比较相等

<if test="loginIpAlias == '1'">
    <choose>
        <when test="loginIpOld != null and loginIpOld != ''">
            <if test="loginIp != null and loginIp != ''">
                and login_ip = #{loginIp}
            </if>
        </when>
        <otherwise>
            and login_ip = #{loginIpOld}
        </otherwise>
    </choose>
</if>

但在运行过程中并没有生效,解决办法,解决方法有两种

  • 将外层双引号改为单引号,如下
<if test='loginIpAlias == "1"'>
  • 使用toString()方法,如下:
<if test="loginIpAlias == '1'.toString()">