問題
- 在MyBatis中if中條件判斷時,由於test裏用了 =, 導致這個if一直處在生效的狀態
<if test="lastResult != null and lastResult != '' and orderStatus = '80'">
AND p.LAST_RESULT = #{lastResult,jdbcType=VARCHAR} AND p.ORDER_STATUS = '80'
</if>
原因
- = 是賦值符號
- == 纔是判斷相等符號
- 另外,如果值爲String, 需要加上toString
<if test="lastResult != null and lastResult != '' and orderStatus == '80'.toString()">
AND p.LAST_RESULT = #{lastResult,jdbcType=VARCHAR} AND p.ORDER_STATUS = '80'
</if>
總結
- 注重基礎操作
- 不能再犯低級錯誤
- 多多練習代碼