1、if <if test="title != null">
2、where像上面的那种情况,如果where后面没有条件,然后需要直接写if判断(开头如果是 and / or 的话,会去除掉) <if test="title != null">
3、choose(when、otherwise) choose 相当于 java 里面的 switch 语句。otherwise(其他情况) <select id="findActiveBlogLike" SELECT * FROM BLOG WHERE state = ‘ACTIVE’ <when test="title != null"> <when test="author != null and author.name != null"> AND author_name like #{author.name}
4、tirmtirm prefix:前缀prefixoverride:去掉第一个and或者是or select * from test
<trim prefix="WHERE" prefixoverride="AND丨OR">
<if test="a!=null and a!=' '">AND a=#{a}<if>
<if test="b!=null and b!=' '">AND a=#{a}<if>
</trim>
5、setset 元素主要是用在更新操作的时候,如果包含的语句是以逗号结束的话将会把该逗号忽略,如果set包含的内容为空的话则会出错。 <update id="dynamicSetTest" parameterType="Blog"> <if test="title != null"> <if test="content != null"> <if test="owner != null">
6、foreachforeach主要用在构建in条件中 <select id="dynamicForeachTest" resultType="Blog"> select * from t_blog where id in <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
open separator close 相当于是in (?,?,?) 如果是个map怎么办 <select id="dynamicForeach3Test" resultType="Blog"> select * from t_blog where title like "%"#{title}"%" and id in <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
collection对应map的键,像这样 List<Integer> ids = new ArrayList<Integer>(); Map<String, Object> params = new HashMap<String, Object>();
|
请发表评论