zoukankan      html  css  js  c++  java
  • mybatis之<trim prefix="" suffix="" suffixOverrides="" prefixOverrides=""></trim>的含义

    转自: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);这样就将“,”去掉了。
    前缀也是一个道理这里就不说了。
  • 相关阅读:
    《aelf经济和治理白皮书》重磅发布:为DAPP提供治理高效、价值驱动的生态环境
    在线直播: .NET与物联网主流技术探秘 初识IoT!
    2019,.Net开发者的高光时刻
    git stash 切换分支以后 恢复
    redis之简单动态字符串(SDS)
    mysql机制总结
    mac 修改用户权限
    sql注入方法以及防范
    redis学习
    mysql百万数据分页查询速度
  • 原文地址:https://www.cnblogs.com/xh_Blog/p/8182335.html
Copyright © 2011-2022 走看看