1.<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);这样就将“,”去掉了。
前缀也是一个道理这里就不说了。

最新文章

  1. 访问 IIS 元数据库失败 的解决方法
  2. iOS 中添加lib型target库的依赖问题
  3. php 数组排序 sort asort ksort
  4. mysql几个命令
  5. 如何高效使用和管理Bitmap--图片缓存管理模块的设计与实现
  6. cf448D Multiplication Table
  7. Margin是什么?
  8. POJ 3380 最大流
  9. vue2.0实现在table中实现全选和反选
  10. This package contains sshd, pcal, mysql-client on Ubuntu14:04
  11. HTML &lt;select&gt;标签
  12. python 类函数,实例函数,静态函数
  13. COGS.1272.[AHOI2009]行星序列(线段树 区间加、乘、求和)
  14. DLL动态链接库导出函数方法 -- 动态导出(.def文件导出)
  15. SqlServer执行大的数据库脚本出错解决方法
  16. Qt Creator中如何添加C++0x支持
  17. Elasticsearch学习之SearchRequestBuilder常用方法说明
  18. java资料——数据结构(转)
  19. cogs [HZOI 2015]有标号的二分图计数
  20. linux 学习第十三天(screen不间断会话、apache服务、SELinux安全子系统)

热门文章

  1. Tensorflow - Implement for generating some 3-dimensional phony data and fitting them with a plane.
  2. hadoop问题集(1)
  3. SGU 194 Reactor Cooling(无源无汇上下界可行流)
  4. Thunder团队Beta周贡献分规则
  5. java线程一之创建线程、线程池以及多线程运行时间统计
  6. ubuntu上的inpack测试
  7. Spring学习(三)—— 自动装配案例分析
  8. lintcode-148-颜色分类
  9. lintcode-11-二叉查找树中搜索区间
  10. Swift-元祖