【MyBatis 4,网易架构师深入讲解Java开发

  <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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值