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>