Mybatis trim 标签使用--insert

trim元素的主要功能是可以在自己包含的内容前加上某些前缀,也可以在其后加上某些后缀,与之对应的属性是prefix和suffix;可以把包含内容的首部某些内容覆盖,即忽略,也可以把尾部的某些内容覆盖,对应的属性是prefixOverrides和suffixOverrides;

<insert id="operatorLog" parameterType="com.oa.model.wxlog.WxLog">
        INSERT INTO sdb_oa_operator_log
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="open_id!=‘‘ and open_id != null">
            open_id,
            </if>
                <if test="operatortime!=‘‘ and operatortime != null">
            operatortime,
            </if>
                <if test="operatortype!=‘‘ and operatortype != null">
            operatortype,
            </if>
                <if test="operatorcont!=‘‘ and operatorcont != null">
            operatorcont,
            </if>
                <if test="ip!=‘‘ and ip != null">
            ip,
            </if>
        </trim>
        <trim prefix="values(" suffix=")" suffixOverrides="," >
            <if test="open_id!=‘‘ and open_id != null">
            #{open_id},
            </if>
                <if test="operatortime!=‘‘ and operatortime != null">
            #{operatortime},
            </if>
                <if test="operatortype!=‘‘ and operatortype != null">
            #{operatortype},
            </if>
                <if test="operatorcont!=‘‘ and operatorcont != null">
            #{operatorcont},
            </if>
                <if test="ip!=‘‘ and ip != null">
            #{ip},
            </if>
        </trim>
    </insert>

原文地址:https://www.cnblogs.com/iscys/p/9550222.html

时间: 2024-07-30 14:10:19

Mybatis trim 标签使用--insert的相关文章

mybatis : trim标签, “等于==”经验, CDATA标签 ,模糊查询CONCAT,LIKE

一.My Batis trim标签有点类似于replace效果. trim 属性, prefix:前缀覆盖并增加其内容 suffix:后缀覆盖并增加其内容 prefixOverrides:前缀判断的条件 suffixOverrides:后缀判断的条件 比如:Java SQL语句如下, select b.* from sys_menu b where 1 = 1 <trim suffix="WHERE" suffixOverrides="AND | OR">

Mybatis源码分析:trim标签

*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; background: #F0F0F0; } /* Base color: saturation 0; */ .hljs, .hljs-subst { color: #444; } .hljs-comment { color: #888888; } .hljs-keyword, .hljs-attribute, .hljs-selector-tag, .hljs-meta-k

MyBatis动态SQL中trim标签的使用

My Batis 官方文档 对 动态SQL中使用trim标签的场景及效果介绍比较少. 事实上trim标签有点类似于replace效果. trim 属性 prefix:前缀覆盖并增加其内容 suffix:后缀覆盖并增加其内容 prefixOverrides:前缀判断的条件 suffixOverrides:后缀判断的条件 比如: Java代码   select b.* from sys_menu b where 1 = 1 <trim suffix="WHERE" suffixOve

Mybatis 常用标签

MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦.拼接的时候要确保不能忘了必要的空格,还要注意省掉列名列表最后的逗号.利用动态 SQL 这一特性可以彻底摆脱这种痛苦. 1.<if> 主要用于sql语句拼接(很简单)如示例 2.<choose,when,otherwise> 有些时候,我们不想用到所有的条件语句,而只想从中择其一二.针对这种情况,MyBatis 提供了 choose

My Batis mapper.xml中 动态SQL中使用trim标签 if end的场景

trim标签有点类似于replace效果. trim 属性 prefix:前缀覆盖并增加其内容 suffix:后缀覆盖并增加其内容 prefixOverrides:前缀判断的条件 suffixOverrides:后缀判断的条件 <!-- 修改 --> <update id="updateTest" >        UPDATE test         <trim prefix="SET" suffixOverrides="

mybatis resultmap标签type属性什么意思

mybatis resultmap标签type属性什么意思? :就表示被转换的对象啊,被转换成object的类型啊 <resultMap id="BaseResultMap" type="BaseObject"> <id property="id" column="id" /> <result property="appId" column="appid"

mybatis &lt;forEach&gt;标签的使用

MyBatis<forEach>标签的使用 你可以传递一个 List 实例或者数组作为参数对象传给 MyBatis.当你这么做的时候,MyBatis 会自动将它包装在一个 Map 中,用名称作为键.List 实例将会以"list"作为键,而数组实例将会以"array"作为键. foreach元素的属性主要有 item,index,collection,open,separator,close.  item表示集合中每一个元素进行迭代时的别名, index

Mybatis中运用小技巧 trim标签的使用

作者:death05的博客推荐:路在脚下trim元素的主要功能是可以在自己包含的内容钱加上某些前缀,也可以在其后加上某写后缀,与之对应的属性是prefix和suffix: 可以把包含内容的首部某些内容覆盖,即忽略,也可以把尾部的某些内容覆盖,对应的属性是prefixOverrides和suffixOverrides.以下举例: 1.代码为: select * from user <trim prefix="WHERE" prefixoverride="AND |OR&q

mybatis动态sql中的trim标签的使用

trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码: 1. select * from user <trim prefix="WHERE" prefixoverride="AND |OR"> <if test="name != null and name.length()>0"> AND name=#{name}</if> <if test="gender