zoukankan      html  css  js  c++  java
  • mybatis批量插入、批量删除

    mybatis
    批量插入
    int addBatch(@Param("list")List<CustInfo> list);
    <insert id="addBatch" parameterType="java.util.List">
    INSERT INTO CUSTINFO(
    SERIALID,
    CUSTID,
    INVNM,
    UPDATETIMESTAMP
    )
    <foreach collection="list" item="item" separator="union all" index="index" >
    ( SELECT 
    #{item.serialid,       jdbcType=VARCHAR},
    #{item.custid,         jdbcType=VARCHAR},
    #{item.invnm,          jdbcType=VARCHAR},
    TO_TIMESTAMP(#{item.updatetimestamp}, 'syyyy-mm-dd hh24:mi:ss.ff')
    FROM DUAL
    )
    </foreach>
    </insert>
    批量删除
    int delCustInfoBatch(@Param("list")List<CustInfo> list);
    <update id="delCustInfoBatch" parameterType="java.util.List" >
    DELETE FROM CUSTINFO
    WHERE SERIALID IN
    <foreach collection="list" item="item" open="(" separator="," close=")"  index="index" >
    #{item.serialid,jdbcType=VARCHAR}
    </foreach>
    </update>


    要做批量插入数据库,首先得知道该数据库对批量插入所支持的语法。

    每一个数据库批量插入的语法都不一样。


    mysql插入
    <insert id="batchSave" parameterType="java.util.List">
    INSERT INTO TABLE_NAME
    ( ID,
    NAME
    )
    VALUES
    <foreach collection="list"  item="item" separator=",">
    ( #{item.id,jdbcType=VARCHAR},
    #{item.name,jdbcType=VARCHAR}
    )
    </foreach>
    </insert>

  • 相关阅读:
    shell 测试命令
    shell 键盘录入和运算
    shell 的变量
    shell 脚本 helloworld
    让windows系统的DOS窗口也可以显示utf8字符集
    wxpython发布还自己图标的程序
    弥补wxpython无背景图片缺陷
    wxPython实现在浏览器中打开链接
    使用py2exe发布windows平台Python
    python os模块实用函数
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5203336.html
Copyright © 2011-2022 走看看