Mybatis的set标签,动态SQL

set标签常用于update语句中,搭配if标签使用

set标签的作用

1、会动态加上前置set关键字

2、可以删除无关的逗号

示例代码:

sql 复制代码
    <update id="update">
        update employee
        <set>
            <if test="name != null">name = #{name},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="idNumber != null">id_number = #{idNumber},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateUser != null">update_User = #{updateUser},</if>
            <if test="status != null">status = #{status},</if>
        </set>
        where id = #{id}
    </update>

set标签和if标签的搭配就可以做到有效适应不同的SQL语句

相关推荐
abcnull5 分钟前
Springboot+Vue2的Web项目小白入门Demo快速学习!
java·elementui·vue·maven·springboot·web·小白
2501_9327502610 分钟前
Java IO流基础全面详解:字节流、字符流
java·开发语言
逸Y 仙X17 分钟前
文章二十二:ElasticSearch EQL事件查询语言
java·大数据·elasticsearch·搜索引擎·全文检索
liulilittle20 分钟前
LLAMA-CLI 运行千问3.6(R9-7945HX+64G+RTX40608G)
java·前端·llama
后端漫漫24 分钟前
Redis 键值对序列化
java·redis
空中海27 分钟前
MyBatis 基础认知、配置体系与核心映射
mybatis
空中海31 分钟前
05 MyBatis 架构设计、渐进式综合项目与专家题库
mybatis
Lenyiin34 分钟前
《LeetCode 顺序刷题》61 - 70
java·c++·python·算法·leetcode·lenyiin
敲代码的瓦龙43 分钟前
Android?基础UI控件!!!
java·开发语言
Hesionberger1 小时前
LeetCode 78:子集生成全攻略
java·开发语言·数据结构·python·算法·leetcode·职场和发展