SELECT tm.id,tm.merchants_name,tm.merchants_type,
tu.name as username,dept.name as deptname,tm.status
FROM t_merchants as tm,t_user as tu,department as dept
WHERE tm.user_id=tu.id AND tu.department_id=dept.id
<if test="merchants_name!=null and merchants_name!='' ">
AND tm.merchants_name LIKE CONCAT('%',#{merchants_name},'%')
</if>
<if test="merchants_type!=null and merchants_type!='' ">
AND tm.merchants_type =#{merchants_type}
</if>
<if test="user_id!=null and user_id!='' and user_id!=0 ">
AND tm.user_id =#{user_id}
</if>
<if test="status!=null and status!='' ">
AND tm.status =#{status}
</if>
if语句在中包裹
SELECT tm.id,tm.merchants_name,tm.merchants_type,
tu.name as username,dept.name as deptname,tm.status
FROM t_merchants as tm,t_user as tu,department as dept
< WHERE>
<if test="merchants_name!=null and merchants_name!='' ">
AND tm.merchants_name LIKE CONCAT('%',#{merchants_name},'%')
</if>
<if test="merchants_type!=null and merchants_type!='' ">
AND tm.merchants_type =#{merchants_type}
</if>
<if test="user_id!=null and user_id!='' and user_id!=0 ">
AND tm.user_id =#{user_id}
</if>
<if test="status!=null and status!='' ">
AND tm.status =#{status}
and tm.user_id=tu.id
AND tu.department_id=dept.id
< /WHERE>
</if>
额粘贴错误了最后的if在{#status}后面