1. if 语句 (简单的条件判断)
<if test="itemOid != null">
item_oid = #{itemOid}
</if> //item_oid 为表的列名,itemOid为传入参数的属性名2. choose (when,otherwize) ,相当于java 语言中的 switch ,与 jstl 中的choose 很类似.(所有的when和otherwise条件中,只有一个会输出)
<choose>
<when test="title != null">
and title = #{title}
</when>
<when test="content != null">
and content = #{content}
</when>
<otherwise>
and owner = "owner1"
</otherwise>
</choose>3. trim (对包含的内容加上 prefix,或者 suffix 等,前缀,后缀)
<trim prefix="where" prefixOverrides="and |or" suffix=""> </trim>
4. where (主要是用来简化sql语句中where条件判断的,能智能的处理 and or ,不必担心多余导致语法错误)
<where>
<if test="title != null">
and title = #{title}
</if>
<if test="content != null">
and content = #{content}
</if>
</where>5. set (主要用于更新时)
<set>
<if test="title != null">
title = #{title},
</if>
<if test="content != null">
content = #{content},
</if>
<if test="owner != null">
owner = #{owner}
</if>
</set>6. foreach (在实现 mybatis in 语句查询时特别有用)
where id in
<foreach collection="list" index="index" item="temp" open="(" separator="," close=")">
#{temp}
</foreach>III-MyBatis 动态sql语句
标签: