zoukankan      html  css  js  c++  java
  • mapper mysl实现批量插入 更新

    1.批量插入

    <insert id="insertConfirm" parameterType="java.util.List">
    insert into `TableName`(id) values
    <foreach collection ="list" item="item" index= "index" separator =",">
    ('${item.id}')
    </foreach >
    </insert>

    2.批量更新
    <update id="updateConfirm" parameterType="java.util.List">
       update `TableName`
    <trim prefix="set" suffixOverrides=",">
    <trim prefix="bgt_stage =case" suffix="end,">
    <foreach collection="list" item="i" index="index">
    <if test="i.bgtstage!=null">
    when tasktypeid='${i.tasktypeid}' and depcode='${i.depcode}' then
    '${i.bgtstage}'
    </if>
    </foreach>
    else bgt_stage
    </trim>
    <trim prefix=" confirmtime =case" suffix="end,">
    <foreach collection="list" item="i" index="index">
    <if test="i.confirmtime!=null">
    when tasktypeid='${i.tasktypeid}' and depcode='${i.depcode}' then
    '${i.confirmtime}'
    </if>
    </foreach>
    else confirmtime
    </trim>
    </trim>
    </update>

    trim 属性

    prefix:前缀覆盖并增加其内容

    suffix:后缀覆盖并增加其内容

    prefixOverrides:前缀判断的条件

    suffixOverrides:后缀判断的条件

                  

  • 相关阅读:
    117. Populating Next Right Pointers in Each Node II
    116. Populating Next Right Pointers in Each Node
    DFS & BFS
    Binary Search
    博客保存
    python强大的正则表达式
    游戏注意的地方
    vim使用
    下一步的
    lua的动态特性
  • 原文地址:https://www.cnblogs.com/sx2zx/p/6341020.html
Copyright © 2011-2022 走看看