一开始的写法
SELECT rrc.id, rrc.resource_name rrc.is_publish FROM res_resource_catalog AS rrc <where> <if test="keyWord != null and keyWord != ‘‘"> AND rrc.resource_name LIKE concat(concat("%",#{keyWord}),"%") OR rrc.resource_abstract LIKE concat(concat("%",#{keyWord}),"%") OR rrc.id IN (SELECT DISTINCT resource_id FROM res_info_item WHERE item_name LIKE concat(concat("%",#{keyWord}),"%")) </if> AND rrc.is_publish = 1 </where>
正确的写法:在<if>里面增加一对()
SELECT rrc.id, rrc.resource_name rrc.is_publish FROM res_resource_catalog AS rrc <where> <if test="keyWord != null and keyWord != ‘‘"> AND (rrc.resource_name LIKE concat(concat("%",#{keyWord}),"%") OR rrc.resource_abstract LIKE concat(concat("%",#{keyWord}),"%") OR rrc.id IN (SELECT DISTINCT resource_id FROM res_info_item WHERE item_name LIKE concat(concat("%",#{keyWord}),"%"))) </if> AND rrc.is_publish = 1 </where>
原文地址:https://www.cnblogs.com/cailijuan/p/11563365.html
时间: 2025-01-22 03:00:13