mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
2018-01-23 14:04
447 查看
1. <trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim> prefix:在trim标签内sql语句加上前缀。 suffix:在trim标签内sql语句加上后缀。 suffixOverrides:指定去除多余的后缀内容,如:suffixOverrides=",",去除trim标签内sql语句多余的后缀","。 prefixOverrides:指定去除多余的前缀内容
2.下面是一个往新闻表中插入数据的mybatis语句 <insert id="insertSelective" parameterType="com.cn.module.news.entity.SwapNews" > insert into swap_news <trim prefix="(" suffix=")" suffixOverrides="," > <if test="id != null" >#{id,jdbcType=VARCHAR},</if> <if test="id == null" >UUID(),</if> <if test="type != null" > type, </if> <if test="title != null" > title, </if> <if test="stitle != null" > stitle, </if> <if test="author != null" > author, </if> <if test="souce != null" > souce, </if> <if test="tags != null" > tags, </if> <if test="summary != null" > summary, </if> <if test="content != null" > content, </if> <if test="picPath != null" > pic_path, </if> <if test="remarks != null" > remarks, </if> <if test="approvalFlag != null" > approval_flag, </if> <if test="isTop != null" > is_top, </if> <if test="delFlag != null" > del_flag, </if> <if test="createUser != null" > create_user, </if> <if test="createTime != null" > create_time, </if> <if test="updateUser != null" > update_user, </if> <if test="updateTime != null" > update_time, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="id != null" > #{id,jdbcType=VARCHAR}, </if> <if test="type != null" > #{type,jdbcType=INTEGER}, </if> <if test="title != null" > #{title,jdbcType=VARCHAR}, </if> <if test="stitle != null" > #{stitle,jdbcType=VARCHAR}, </if> <if test="author != null" > #{author,jdbcType=VARCHAR}, </if> <if test="souce != null" > #{souce,jdbcType=VARCHAR}, </if> <if test="tags != null" > #{tags,jdbcType=VARCHAR}, </if> <if test="summary != null" > #{summary,jdbcType=VARCHAR}, </if> <if test="content != null" > #{content,jdbcType=LONGVARCHAR}, </if> <if test="picPath != null" > #{picPath,jdbcType=VARCHAR}, </if> <if test="remarks != null" > #{remarks,jdbcType=VARCHAR}, </if> <if test="approvalFlag != null" > #{approvalFlag,jdbcType=INTEGER}, </if> <if test="isTop != null" > #{isTop,jdbcType=INTEGER}, </if> <if test="delFlag != null" > #{delFlag,jdbcType=INTEGER}, </if> <if test="createUser != null" > #{createUser,jdbcType=VARCHAR}, </if> <if test="createTime != null" > #{createTime,jdbcType=TIMESTAMP}, </if> <if test="updateUser != null" > #{updateUser,jdbcType=VARCHAR}, </if> <if test="updateTime != null" > #{updateTime,jdbcType=TIMESTAMP}, </if> </trim> </insert>
假设没有指定
suffixOverrides=","
执行的sql语句也许是这样的:insert into swap_news(id,type,title,) values(1,2,哈哈哈,);显然是错误的
指定之后语句就会变成insert into swap_news(id,type,title,) values(1,2,哈哈哈);这样就将“,”去掉了。
前缀也是一个道理这里就不说了。
相关文章推荐
- mybatis中sql中的特殊符号<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
- mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
- mybatis中的<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>说明
- Mybatis使用“<trim prefix="SET" suffixOverrides=",">”出现Cause: java.sql.SQLException:
- Mybatis最入门---动态查询( <trim prefix="where" prefixOverrides="and|or"> )
- mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
- mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
- mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>
- <trim>: prefix+prefixOverrides+suffix+suffixOverrides
- mybatis insert 空属性用trim suffix="" suffixOverrides=","去多余的“,”
- mybatis insert 空属性用trim suffix="" suffixOverrides=","去多余的“,”
- <trim>: prefix+prefixOverrides+suffix+suffixOverrides
- <trim>: prefix+prefixOverrides+suffix+suffixOverrides
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- 【mybatis】IF判断的坑 (实现<if test=" status == 'zhangsan'">)
- Mybatis使用<foreach collection="***" item="**" open="(" separator="," close=")">问题
- myBatis中,对">"或者"<"的处理
- mybatis(ibatis)中的动态sql<dynamic prepend="where"><isNotEmpty>的讲解
- Mybatis <trim> 用法
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>报错