MyBatis <set>标签的使用

阅读数:289 评论数:0

跳转到新版页面

分类

python/Java

正文

一、概述

mybatis原来是apache的一个开源项目,叫做ibatis,2010年由apache迁移到了google code,并且改名为mybatis。2013年迁移到github。

mybatis中文文档: https://mybatis.net.cn/

github: https://github.com/mybatis/mybatis-3

二、set标签

set元素会动态地在行首插入set关键字,并会删除额外的逗号,用于动态更新语句。

<update id="updateByPrimaryKeySelective" parameterType="RecruitmentConfBanner">
        UPDATE conf_banner t
<!--等价于 <trim prefix="set" suffixOverrides=","> -->
        <set> 
            <if test="bannerName != null">
                t.banner_name = #{bannerName},
            </if>
            <if test="bannerUrl != null">
                t.banner_url = #{bannerUrl},
            </if>
            <if test="bannerLogo != null">
                t.banner_logo = #{bannerLogo},
            </if>
            <if test="bannerDescription != null">
                t.banner_description = #{bannerDescription},
            </if>
            <if test="sort != null">
                t.sort = #{sort},
            </if>
             <if test="isEnabled != null">
                t.is_enabled = #{isEnabled},
            </if>
        </set>
        where t.banner_id = #{bannerId}
    </update>



相关推荐

出现这个错误,是因为mybatis默认OGNL解析参数,所以会自动采用对象树形式取String.xxx值。 解决方法: 方法1:在方法中提前定义 <pre c

&lt;if test="extraSql != null and extraSql !=''"&gt; AND ${ext

(1)Executor 执行增删改查操作

实际开发中,有时候需要把当前插入的数据id取出来,但又不想再去查一遍. mybatis提供了两种返回insert方法后的主键的方法 : 1、根据useGeneratedKeys获取

一、概述 一个项目使用多个数据库(无论是主从复制--读写分离还是分布式数据库结构)的重要性变得越来越明显,整合的多数据源有两种方式:分包和aop。 1、SqlSessionTemplate SqlSe

背景: 之前用spring boot+mybatis+oracle,现在要改成spring boot_mybatis+postgresql。 为了想让一套代码即可

1、使用selectKey标签 &lt;insert id="addLoginLog" parameterTyp

依靠数据库锁是非常安全的方式,比方说,分布式定时任务,除了使用quartz不让各个机器上同时跑一个定时任务之外,最好在数据库也加一个保险。插入一条数据之前,判断表中有没有这条数据,如果没有才插入

原因很简单,就一句话,是不是resultType 和resultMap 弄混了? &nbsp; 大致的意思就是无法找到返回值对应的r

当我们进行web开发的时候总是看到配置的log4j日志在控制台无法显示mybatis的主要是指sql、参数、结果,出现这种问题有两种情况: 情部1:</strong