转自:http://blog.csdn.net/qq_33054511/article/details/70490046
 
<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
prefix:在trim标签内sql语句加上前缀。
suffix:在trim标签内sql语句加上后缀。
suffixOverrides:指定去除多余的后缀内容,如:suffixOverrides=",",去除trim标签内sql语句多余的后缀","。
prefixOverrides:指定去除多余的前缀内容
2.下面是一个往购物车表中插入数据的mybatis语句

 
  1. <insert id="insert" parameterType="com.tortuousroad.groupon.cart.entity.Cart">
  2. insert into cart
  3. <trim prefix="(" suffix=")" suffixOverrides=",">
  4. <if test="id != null">
  5. id,
  6. </if>
  7. <if test="userId != null">
  8. user_id,
  9. </if>
  10. <if test="dealId != null">
  11. deal_id,
  12. </if>
  13. <if test="dealSkuId != null">
  14. deal_sku_id,
  15. </if>
  16. <if test="count != null">
  17. count,
  18. </if>
  19. <if test="createTime != null">
  20. create_time,
  21. </if>
  22. <if test="updateTime != null">
  23. update_time,
  24. </if>
  25. </trim>
  26. <trim prefix="values (" suffix=")" suffixOverrides=",">
  27. <if test="id != null">
  28. #{id,jdbcType=BIGINT},
  29. </if>
  30. <if test="userId != null">
  31. #{userId,jdbcType=BIGINT},
  32. </if>
  33. <if test="dealId != null">
  34. #{dealId,jdbcType=BIGINT},
  35. </if>
  36. <if test="dealSkuId != null">
  37. #{dealSkuId,jdbcType=BIGINT},
  38. </if>
  39. <if test="count != null">
  40. #{count,jdbcType=INTEGER},
  41. </if>
  42. <if test="createTime != null">
  43. #{createTime,jdbcType=TIMESTAMP},
  44. </if>
  45. <if test="updateTime != null">
  46. #{updateTime,jdbcType=TIMESTAMP},
  47. </if>
  48. </trim>
  49. </insert>
假设没有指定

  1. 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>

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

  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. Postman-CI集成Jenkins(3)

    Postman-CI集成Jenkins(3) Postman-简单使用 Postman-进阶使用 Postman-CI集成Jenkins Newman 官方说明:Postman's command-l ...

  2. DDT驱动

    下载ddt并安装 Pip install ddt 或者官网下载安装 http://ddt.readthedocs.io/en/latest/ https://github.com/txels/ddt ...

  3. Python全栈工程师(数值类型、运算符)

    ParisGabriel       Python 入门基础     python的应用领域: 1.系统运维 2.网络编程(如:网络爬虫,搜索引擎,服务器编程) 3.科学计算 4.航空领域(如:卫星, ...

  4. PHP连接mysql数据库进行增删改查--修稿数据

    <?php $id = $_GET['id']; $db = new Mysqli("localhost","root","root" ...

  5. 团队项目-任务分解[Alpha0]

    团队项目-任务分解[Alpha0] 标签(空格分隔): 团队博客 适用范围: 本文档 适用对象 团队全体成员 适用时间 alpha阶段第一周计划 10.24-10.28 适用内容 目标.分工.时长估计 ...

  6. 团队冲刺Alpha(九)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  7. spring 配置问题记录1-@ResponseBody和favorPathExtension

    在搭建springmvc+easyui的项目时,有一个地方参照网上说的方法一直没实现出来, 就是前台的datagrid的数据渲染不上去, 尝试了好多种方法,包括也找了目前手里的项目来进行比较,也没发现 ...

  8. 软考——(5)计算机系统之CPU组成

    其实我们很早就接触过计算机系统方面的知识,但是还是出现印象不深,理解不清楚的现象,丢分很严重.这部分的知识需要我们花功夫去理解,因为很多东西我们接触不到,比如校验码.码制等,如果你不去理解而是去记,就 ...

  9. 如何将查询到的数据显示在DataGridView中

    背景介绍: 数据库中的T_Line_Info表中存放着学生上机的记录,也就是我们需要查询上机记录的表,其中具体内容为: 界面设计如下: 右击DataGridView控件,选择编辑列,设计它的列名. 代 ...

  10. nginx限速白名单配置

    在<nginx限制连接数ngx_http_limit_conn_module模块>和<nginx限制请求数ngx_http_limit_req_module模块>中会对所有的I ...