<select id="getDocsByCondition" resultType="Doc">
select * from t_doc
<where>
<if test="data != null and data != ''">
<trim prefix="(" suffix=")">
<if test="method == 0 or method == null">
title like '%${data}%'
or content like '%${data}%'
</if>
</trim>
<if test="method == 1 ">
title like '%${data}%'
</if>
<if test="method == 2 ">
content like '%${data}%'
</if>
</if>
<if test="deptId != null and deptId != 0">
and dept_id = #{deptId}
</if>
<if test="typeId != null and typeId != 0">
and type_id = #{typeId}
</if>
</where>
</select>
直接使用
<trim prefix="(" suffix=")">
</trim>
将要加括号的语句放在这个trim标签里面即可