mapper的前后缀
2024-10-20 04:45:10
1.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
prefix:在trim标签内sql语句加上前缀。
suffix:在trim标签内sql语句加上后缀。
suffixOverrides:指定去除多余的后缀内容,如:suffixOverrides=",",去除trim标签内sql语句多余的后缀","。
prefixOverrides:指定去除多余的前缀内容
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);这样就将“,”去掉了。
前缀也是一个道理这里就不说了。
最新文章
- 访问 IIS 元数据库失败 的解决方法
- iOS 中添加lib型target库的依赖问题
- php 数组排序 sort asort ksort
- mysql几个命令
- 如何高效使用和管理Bitmap--图片缓存管理模块的设计与实现
- cf448D Multiplication Table
- Margin是什么?
- POJ 3380 最大流
- vue2.0实现在table中实现全选和反选
- This package contains sshd, pcal, mysql-client on Ubuntu14:04
- HTML <;select>;标签
- python 类函数,实例函数,静态函数
- COGS.1272.[AHOI2009]行星序列(线段树 区间加、乘、求和)
- DLL动态链接库导出函数方法 -- 动态导出(.def文件导出)
- SqlServer执行大的数据库脚本出错解决方法
- Qt Creator中如何添加C++0x支持
- Elasticsearch学习之SearchRequestBuilder常用方法说明
- java资料——数据结构(转)
- cogs [HZOI 2015]有标号的二分图计数
- linux 学习第十三天(screen不间断会话、apache服务、SELinux安全子系统)
热门文章
- Tensorflow - Implement for generating some 3-dimensional phony data and fitting them with a plane.
- hadoop问题集(1)
- SGU 194 Reactor Cooling(无源无汇上下界可行流)
- Thunder团队Beta周贡献分规则
- java线程一之创建线程、线程池以及多线程运行时间统计
- ubuntu上的inpack测试
- Spring学习(三)—— 自动装配案例分析
- lintcode-148-颜色分类
- lintcode-11-二叉查找树中搜索区间
- Swift-元祖