您的位置:首页 > 数据库

mybatis动态sql语句

2014-08-09 18:05 405 查看
在动态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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: