MyBatis-动态SQL

<if>标签

用于判断条件是否成立,使用test属性进行条件判断,如果条件为true,则拼接SQL

<where>标签

where元素只会在子元素有内容的情况下插入where子句,而且会自动去除子句的开头的AND或OR

复制代码
<where>
    <if test="name!=null">
        name like concat('%',#(name),"%")
    </if>
</where>

<set>:动态地在行首插入SET关键字,并会删掉额外的逗号(用在update语句中)

<foreach>标签

SQL语句

delete from emp where id in (1,2,3);

接口方法:

public void deleteBylds(List<Integer> ids);

XML映射文件:

<delete id ="deleteBylds">

delete from emp where id in

<foreach collection ="ids" item="id" sepatator="," open="(" close=")">

#{id}

</foreach>

</delete>

属性:

collection:集合名称

item:集合遍历出来的元素

sepatator:每一次遍历使用的分隔符

open:遍历开始前拼接的片段

close:遍历结束后拼接的片段

sql片段

<sql>:定义可重用的SQL片段

<include>:通过属性refid,指定包含的sql片段

相关推荐
考虑考虑1 天前
Jpa使用union all
java·spring boot·后端
用户3721574261351 天前
Java 实现 Excel 与 TXT 文本高效互转
java
浮游本尊1 天前
Java学习第22天 - 云原生与容器化
java
渣哥1 天前
原来 Java 里线程安全集合有这么多种
java
间彧1 天前
Spring Boot集成Spring Security完整指南
java
间彧1 天前
Spring Secutiy基本原理及工作流程
java
Java水解1 天前
JAVA经典面试题附答案(持续更新版)
java·后端·面试
洛小豆1 天前
在Java中,Integer.parseInt和Integer.valueOf有什么区别
java·后端·面试
前端小张同学1 天前
服务器上如何搭建jenkins 服务CI/CD😎😎
java·后端
ytadpole1 天前
Spring Cloud Gateway:一次不规范 URL 引发的路由转发404问题排查
java·后端