zoukankan      html  css  js  c++  java
  • Java通过Mybatis实现批量插入数据到Oracle中

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.oracle.mapper.AccountInfoMapper"><!--  接口的全类名 -->
        <!-- type:实体类的全类名 -->
        <resultMap id="BaseResultMap" type="com.oracle.entity.AccountInfo">
            <id column="ID" property="id" jdbcType="DECIMAL" />
            <result column="USERNAME" property="userName" jdbcType="VARCHAR" />
            <result column="PASSWORD" property="password" jdbcType="VARCHAR" />
            <result column="GENDER" property="gender" jdbcType="CHAR" />
            <result column="EMAIL" property="email" jdbcType="VARCHAR" />
            <result column="CREATE_DATE" property="createDate" jdbcType="DATE" />
        </resultMap>
        <!-- id 跟接口中的方法名称保持一致 -->
        <select id="queryAllAccountInfo" resultMap="BaseResultMap">
            select ID,
            USERNAME,PASSWORD,
            GENDER, EMAIL, CREATE_DATE from ACCOUNT_INFO
        </select>
        <insert id="batchInsertAccountInfo" parameterType="java.util.List">
            INSERT INTO ACCOUNT_INFO(ID, USERNAME,PASSWORD,GENDER, EMAIL,CREATE_DATE)
            (
            <foreach collection="list" index="" item="accountInfo"
                separator="union all">
                select
                #{accountInfo.id},
                #{accountInfo.userName},
                #{accountInfo.password},
                #{accountInfo.gender},
                #{accountInfo.email},
                #{accountInfo.createDate}
                from dual
            </foreach>
            )
        </insert>
        
        <insert id="batchInsertAccountInfoUseSeq" parameterType="java.util.List">
            <selectKey resultType="long" keyProperty="id" order="BEFORE"> 
                SELECT ACCOUNT_SEQ.NEXTVAL FROM dual
            </selectKey> 
            INSERT INTO ACCOUNT_INFO(ID, USERNAME,PASSWORD,GENDER, EMAIL,CREATE_DATE)
            SELECT ACCOUNT_SEQ.NEXTVAL, m.* FROM(
            <foreach collection="list" index="" item="accountInfo"
                separator="union all">
                select
                #{accountInfo.userName},
                #{accountInfo.password},
                #{accountInfo.gender},
                #{accountInfo.email},
                sysdate
                from dual
            </foreach>
            ) m
        </insert>
        
        <insert id="insertOne" parameterType="com.oracle.entity.AccountInfo">
            <selectKey resultType="long" keyProperty="id" order="BEFORE"> 
                SELECT ACCOUNT_SEQ.NEXTVAL FROM dual
            </selectKey> 
            INSERT INTO ACCOUNT_INFO(ID, USERNAME,PASSWORD,GENDER, EMAIL,CREATE_DATE)
            values(
                #{id},
                #{userName},
                #{password},
                #{gender},
                #{email},
                sysdate
            )
        </insert>
    </mapper>
  • 相关阅读:
    SQL 学习笔记<六> MySQL存储过程基础
    SQL 学习笔记<三> SELECT之连接查询
    六、Delphi10.3通过Json.Serializers单元对大量数据序列化
    七、Delphi10.3读取JSON数组
    五、Delphi10.3通过REST单元使类和JSON数据互相转换
    四、Delphi10.3读取JSON数据
    python格式化输出
    python基础知识02
    发送邮件实例
    python基础知识03
  • 原文地址:https://www.cnblogs.com/zhaoyan001/p/9318820.html
Copyright © 2011-2022 走看看