MyBatis中if裏的test條件等值判斷問題

MyBatis中的if語句

問題

  • MyBatisif中條件判斷時,由於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>

總結

  • 注重基礎操作
  • 不能再犯低級錯誤
  • 多多練習代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章