mybatis where-if中if不能识别大写AND,OR

mybatis报错:Caused by: org.apache.ibatis.ognl.ParseException: Encountered ” “AND “” at line 1

错误代码:

  <select id="selectAccountList" resultMap="BaseResultMap">
  	SELECT ct.customer_name customerName,sam.city_code,sam.user_name,sam.account_name
		FROM sys_account_manager sam LEFT JOIN sys_customer ct ON ct.id = sam.customer_id 
	  WHERE sam.deleted = 0
	  <if test="customerName != null AND customerName != '' ">
	  	AND ct.customer_name LIKE concat('%',#{customerName},'%')
	  </if>
	  <if test="cityCode != null AND cityCode != '' ">
	  	AND LOCATE(#{cityCode},sam.city_code)
	  </if>
	  order by status,account_validity_time DESC
  </select>

正确代码:
原因是:if条件中AND为大写,大写不能识别,应改为小写。

<select id="selectAccountList" resultMap="BaseResultMap">
  	SELECT ct.customer_name customerName,sam.city_code,sam.user_name,sam.account_name
		FROM sys_account_manager sam LEFT JOIN sys_customer ct ON ct.id = sam.customer_id 
	  WHERE sam.deleted = 0
	  <if test="customerName != null and customerName != '' ">
	  	AND ct.customer_name LIKE concat('%',#{customerName},'%')
	  </if>
	  <if test="cityCode != null and cityCode != '' ">
	  	AND LOCATE(#{cityCode},sam.city_code)
	  </if>
	  order by status,account_validity_time DESC
  </select>
    原文作者:↘"LYong
    原文地址: https://blog.csdn.net/weixin_39093006/article/details/91041819
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞