<if test="password != null">password=#{password},</if>
<if test="email != null">email=#{email},</if>
<if test="address != null">ddress=#{ddress}</if>
</trim>
where id=#{id}
### 4、if
SELECT * FROM user WHERE 1 = 1
AND position like #{position}
### 5**、choose、when、otherwish**
SELECT * FROM user WHERE 1 = 1
<when test="position != null">
AND position like #{position}
</when>
<when test="department != null and department.name != null">
AND department_name like #{department.name}
</when>
<otherwise>
AND department_name = '公司'
</otherwise>
### 6、foreach
SELECT id,name,age,sex,address,school FROM user u
WHERE id in
<foreach item=“item” index=“index” collection=“list”
open="(" separator="," close=")">
#{item}
当使用可迭代对象或者数组时,index 是当前迭代的次数,item 的值是本次迭代获取的元素。
当使用 Map 对象(或者 Map.Entry 对象的集合)时,index 是键,item 是值。
INSERT INTO s c h e m a N a m e . {schemaName}. schemaName.{tableName}
<foreach collection="map.keys" item="key" open="(" separator="," close=")">
${key}
</foreach>
VALUES
<foreach collection="map.entrySet()" open="(" separator="," close=")" index="key" item="val">
<choose>
<when test='key.contains("date")'>
to_date(#{val}, 'yyyy-MM-dd HH24:mi:ss')
</when>
<otherwise>
#{val}
</otherwise>
</choose>
</foreach>
### 7、bind
SELECT * FROM user
WHERE dept_id = #{dept}
### 8、连接多数据库
<if test="_databaseId == 'oracle'">
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
</if>
<if test="_databaseId == 'mysql'">
select now() as Systemtime
</if>
往期精彩内容:
[Java知识体系总结](https://gitee.com/vip204888/java-p7)
[Spring框架总结](https://gitee.com/vip204888/java-p7)
[超详细的springBoot学习笔记](https://gitee.com/vip204888/java-p7)
# 最后
各位读者,由于本篇幅度过长,为了避免影响阅读体验,下面我就大概概括了整理了,需要的话请**[点赞后点击这里免费下载文章资料!](https://gitee.com/vip204888/java-p7)**
![](https://img-blog.csdnimg.cn/img_convert/b4d05fe6c4e6c4644885b688cc4b83d8.png)
![](https://img-blog.csdnimg.cn/img_convert/f60c07bf77518209bac3e83d62417a5e.png)
![](https://img-blog.csdnimg.cn/img_convert/fc5eead9998a8146314eba0c437ed046.png)
长,为了避免影响阅读体验,下面我就大概概括了整理了,需要的话请**[点赞后点击这里免费下载文章资料!](https://gitee.com/vip204888/java-p7)**
[外链图片转存中...(img-EMHMwQox-1628508311824)]
[外链图片转存中...(img-8AxK7Kjq-1628508311827)]
[外链图片转存中...(img-rJdx2YPk-1628508311829)]
![](https://img-blog.csdnimg.cn/img_convert/5a568e0c1fe5600ca346b47e41b0d816.png)