Java通過Mybatis實現批量插入資料到Oracle中

來源:互聯網
上載者:User

標籤:union all   ted   creat   sys   arch   from   bat   pac   result   

<?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>

 

Java通過Mybatis實現批量插入資料到Oracle中

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.