![38933976f8a7191e0ab4f321f9354ced.png](https://i-blog.csdnimg.cn/blog_migrate/90cf301e42cc2624db10dfec2c4f2b63.jpeg)
1.<resultMap> 通常用于做实体类和数据库表之间的映射,当查询的返回值为实体类的时候,可以直接返回相对应的<resultMap>。
2.<sql id="Base_Column_List">当需要查询的字段经常用到,就可以用sql标签来包装,当想要使用的时候使用<include refid="Base_Column_List"/>进行使用。
3.trim标签的使用:
<trim prefix="(" suffix=")" suffixOverrides=",">
prefix:前缀覆盖并添加其内容
suffix:后缀覆盖并添加其内容
prefixOverrides:前缀判断条件
suffixOverrides:后缀判断条件
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="guid != null">
guid,
</if>
<if test="userMail != null">
user_mail,
</if>
<if test="userGuid != null">
user_guid,
</if>
<if test="userName != null">
user_name,
</if>
<if test="status != null">
status,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="createUserEmail != null">
create_user_email,
</if>
<if test="updateUserEmail != null">
update_user_email,
</if>
</trim>
4.if 标签使用
<if test="userName != null">
user_name,
</if>
主要用于测试使用的字段是否为空。
5. foreach标签的使用
<foreach collection="users" item="p" open="" close=""
separator=",">
主要用于对于集合的操作,一般入参的数据类型都为Map。
collection为Map的key的类型
<foreach collection="users" item="p" separator=",">
(#{p.guid},
#{p.userMail},
#{p.userGuid},
#{p.userName},
1,
#{p.createUserEmail},
#{p.updateUserEmail},
#{p.deptId},
#{p.isOwer})
</foreach>
6.choose标签的使用
<choose>
<when test="p.userName != null">#{p.userName},</when>
<otherwise>null,</otherwise>
</choose>
主要用于对字段的条件的判断,一般搭配otherwise来使用。
<foreach collection="users" item="p" open="" close=""
separator=",">
<trim prefix="(" suffix=")">
<choose>
<when test="p.userName != null">#{p.userName},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="p.deptId != null">#{p.deptId},</when>
<otherwise>null,</otherwise>
</choose>
<choose>
<when test="p.isOwer != null">#{p.isOwer},</when>
<otherwise>0,</otherwise>
</choose>
<choose>
<when test="p.userMail != null">#{p.userMail}</when>
<otherwise>null</otherwise>
</choose>
</trim>
</foreach>