zoukankan      html  css  js  c++  java
  • Mybatis批量插入

    批量插入在oracle和mysql中配置几乎一致,但是sql语句不同。

    oracle配置如下

        <insert id="setRoles" parameterType="java.util.List">
            insert into role  
            <foreach collection="list" item="role" index="index" separator="union all">
                select #{role.roleID},#{role.moduleID},#{role.roleName},#{role.grade},#{role.roleID} from dual
            </foreach>
        </insert>

    mysql配置如下

        <insert id="insertByBatch" parameterType="java.util.List">
            insert into attachment_table (name, logID,url)
            values
            <foreach collection="list" item="item" index="index" separator=",">
                (#{item.name,jdbcType=VARCHAR}, #{item.logid,jdbcType=INTEGER},#{item.url,jdbcType=LONGVARCHAR})
            </foreach>
        </insert>

    注意其中

    1、oracle的插入语句里没有values

    2、oracle的foreach循环中使用的是select **** from dual

    这两种不同的方式,输入的日志格式也不同。

    oracle :

     insert into role select ?,?,?,?,? from dual union all select ?,?,?,?,? from dual union all select ?,?,?,?,? from dual 

    mysql :

     insert into role values(?,?,?,?,?),(?,?,?,?,?)

    由于oracle中没有mysql的这种插入方式,才导致两种不同数据库需要两种不同的批量插入方式。

    具体的配置当中,foreach是一个循环标签,由于我们的传入参数是list,所以collection的值为list;item代表list中每一个对象的名称

  • 相关阅读:
    Mysql 用户管理
    php插件名称 yum安装
    U盘模式无法引导进入pe系统
    修改 ssh 远程连接 时间
    tomcat 安装在 linux
    tomcat 配置文件 server.xml
    Linux 安装 jdk
    高可用web架构: LVS+keepalived+nginx+apache+php+eaccelerator(+nfs可选 可不选)
    Keepalived 工作原理和配置说明
    Mysql 初始化 及 密码管理
  • 原文地址:https://www.cnblogs.com/yxth/p/6673802.html
Copyright © 2011-2022 走看看