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>
总结
  • 注重基础操作
  • 不能再犯低级错误
  • 多多练习代码