今日思語:受過生活的虐,很容易愛上 四下無人的街,對酒當歌的夜~
在處理判斷條件時,經常會以某個值進行判斷走不同的邏輯,mybatis中判斷字符串相等時,如下:
<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>
但在運行過程中並沒有生效,解決辦法:
1、將外層雙引號改為單引號,如下:
<if test='loginIpAlias == "1"'>
2、使用toString()方法,如下:
<if test="loginIpAlias == '1'.toString()">
以上處理方式就可以解決字符串判斷失效的問題