在动态sql语句中trim 是prefix="WHERE" prefixOverrides="AND |OR "需要添加的,这是一个模糊查询
<select id="getInfoLogForTrim" parameterType="InfoLog" resultType="InfoLog">
select * from info_log
<trim prefix="WHERE" prefixOverrides="AND |OR ">
<if test="operator != null">
and operator like '%'|| #{operator}||'%'
</if>
<if test="mac != null ">
and <![CDATA[ mac =#{mac}]]>
</if>
<if test="annex != null">
and annex =#{annex}
</if>
</trim>
</select>
动态中的where语法
<select id="getInfoLogForWhere" parameterType="InfoLog" resultType="InfoLog">
select * from info_log
<where>
<if test="operator != null">
and operator like '%'|| #{operator}||'%'
</if>
<if test="mac != null ">
and <![CDATA[ mac =#{mac}]]>
</if>
<if test="annex != null">
and annex =#{annex}
</if>
</where>
</select>