1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>

prefix:在trim标签内sql语句加上前缀。

suffix:在trim标签内sql语句加上后缀。


prefixOverrides:指定去除多余的前缀内容

suffixOverrides:指定去除多余的后缀内容,如:suffixOverrides=",",去除trim标签内sql语句多余的后缀","。

2.下面是一个往购物车表中插入数据的mybatis语句

<insert id="insert" parameterType="com.tortuousroad.groupon.cart.entity.Cart">
insert into cart
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="userId != null">
user_id,
</if>
<if test="dealId != null">
deal_id,
</if>
<if test="dealSkuId != null">
deal_sku_id,
</if>
<if test="count != null">
count,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="userId != null">
#{userId,jdbcType=BIGINT},
</if>
<if test="dealId != null">
#{dealId,jdbcType=BIGINT},
</if>
<if test="dealSkuId != null">
#{dealSkuId,jdbcType=BIGINT},
</if>
<if test="count != null">
#{count,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>

假设没有指定

suffixOverrides=","

执行的sql语句也许是这样的:insert into cart (id,user_id,deal_id,) values(1,2,1,);显然是错误的

指定之后语句就会变成insert into cart (id,user_id,deal_id) values(1,2,1);这样就将“,”去掉了。

前缀也是一个道理这里就不说了。

mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>的更多相关文章

  1. mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>的含义

    转自:http://blog.csdn.net/qq_33054511/article/details/70490046   <trim prefix="" suffix=& ...

  2. <trim>: prefix+prefixOverrides+suffix+suffixOverrides

    <trim prefix="where" prefixOverrides="where" suffixOverrides="and"& ...

  3. Mybatis学习笔记11 - 动态sql之trim标签

    trim标签体中是整个字符串拼串后的结果.prefix="" 前缀: prefix给拼串后的整个字符串加一个前缀prefixOverrides="" 前缀覆盖: ...

  4. CSAcademy Prefix Suffix Counting 题解

    CSAcademy Prefix Suffix Counting 题解 目录 CSAcademy Prefix Suffix Counting 题解 题意 思路 做法 程序 题意 给你两个数字\(N\ ...

  5. mybatis之<trim

    1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=&quo ...

  6. MyBatis-动态SQL的if、choose、when、otherwise、trim、where、set、foreach使用(各种标签详解), 以及实体间关系配置

    比较全的文档:https://www.cnblogs.com/zhizhao/p/7808880.html 或 https://blog.csdn.net/zhll3377/article/detai ...

  7. mybatics之trim

    1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=&quo ...

  8. MyBatis的动态sql小练习,小回顾

    关键字if+trim trim可以去除多余的关键字,是where和set的组合 trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码: <trim prefix=& ...

  9. mapper的前后缀

    1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=&quo ...

随机推荐

  1. 关于scanf的一些知识

    10.22,对现阶段已知道的scanf的一些用法或注意事项的一些总结: 1.scanf中,赋值的那个数据前面一定加&! 2.若情景要求必须输入空格的,scanf("%d%c%d&qu ...

  2. HTML页面导入模板页面(Tomcat)

    找了个前端模板,多个HTML中有重复的部分,一改都改,所以对其进行重构,将重复的部分拿出来 看了很多方法,最简单的是jQuery,但是在我这没起作用,后来发现一个配置tomcat的ssi,让服务器帮我 ...

  3. OpenDaylight开发hello-world项目之代码框架搭建

    OpenDaylight开发hello-world项目之开发环境搭建 OpenDaylight开发hello-world项目之开发工具安装 OpenDaylight开发hello-world项目之代码 ...

  4. Python连载49-正则举例

    一.re举例 import re #查找数字 p = re.compile(r"\d+") #在字符串“ongahjeuf125”中及逆行查找,按照规则p指定的正则进行查找 m = ...

  5. linux下通过命令行把文件拷贝到U盘上

    常用linux,往U盘拷贝文件是常用的一种方法.下面这个方法是笔者亲测有效,暂时记录下来. 1.插入U盘,fdisk -l查看U盘是哪个设备(比如/dev/sdb1)然后mount  /dev/sdb ...

  6. Unity TextMeshPro 一键生成工具

    本文参考了这片博客文章,在此基础上进行优化和改进: https://blog.csdn.net/akof1314/article/details/80868869 先截张效果图: TextMeshPr ...

  7. 序列化禁止使用Optional

    1: 概论 Optional 是Java8用来改变java引发NPE的解决办法,但是不是绝对的解决办法 2: 例子: 很多博文一上来就给力以下使用例子 @Data public class User ...

  8. pixijs shader 案例

    pixijs shader 案例 const app = new PIXI.Application({ transparent: true }); document.body.appendChild( ...

  9. npm install 安装依赖报错

    npm ERR! Unexpected end of JSON input while parsing near '...2.4.8","karma":"~0. ...

  10. 【广州.NET社区推荐】.NET Core Q&A - ORM

    Object/Relational Mapping(ORM) 作为开发工作中非常重要的组件,重量级.轻量级.简单的.复杂的 各种各样有很多种适应不同的业务场景,但这些组件分散在网络世界的各个角落,寻找 ...