1. <if> (single condition)
2, <choose> <when> (multiple branch conditions)
3, <where> for intelligent processing where conditions, can be intelligent to add and remove conditions and
<select>
SELECT * FROM user
<where>
<if test= "UserName! = null" >
and userName like #{username}
</if>
<if test= "id!= null" >
and Id= #{id}
</if>
</where>
</select>
4, <set> processing update operation, you can intelligently remove or add the comma inside the set
<update>
Update user
<set>
<if test= "UserName! = null" > username=#{username},</if>
<if test= "password!= null" > Password=#{password},</if>
</set>
</update>
5. <trim> can automatically add prefixes and suffixes to SQL to reduce prefix characters or suffix characters
<update>
Update user
<trim prefix= "Set" suffixoverride= "," suffix= "where Id=#{id}" >
<if test= "Username!=null and username!=" >
Username=#{username},
</if>
<if test= "Password!=null and password!=" >
Password=#{password},
</if>
</trim>
</update>
6, Foreach Loop flag, mainly used for cyclic query conditions, circular update
Circular query Condition:
<select>
SELECT * FROM user
<where>
ID in
<foreach item= "Item" index= "index" collection= "list" open= "(" separator= "," close= ")" >
#{item}
</foreach>
</where>
</select>
Batch assignment:
<insert>
Insert into User (Username,password)
Values
<foreach item= "Item" index= "index" collection= "list" open= "" close= "" separator= "," >
(#{item.username},#{item.password})
<foreach>
</insert>
Explain:
An element that the item loops to
Index of an index loop
Collection of collection Loops
Start symbol for Open loop
Closing symbol for Close loop
MyBatis Dynamic SQL (ii)