mybatis oracle批量插入數據


 

方式一

<insert id="addBatch" parameterType="java.util.List">  
    BEGIN  
    <foreach collection="list" item="item" index="index" separator="">  
        insert into test  
        (userid,username createdate)  
        VALUES  
        (  
        #{item.userId,jdbcType=INTEGER},
        #{item.username,jdbcType=VARCHAR},#{item.createDate,jdbcType=DATE});  
    </foreach>  
    COMMIT;  
    END;  
</insert>  

 

方式二

(適用oracle。去掉foreach中的open="(" close=")" 適用於mysql和oracle)

<insert id="addBatch"  parameterType="java.util.List">  
    INSERT INTO test (userid,username createdate 
    )  
    <foreach open="("  close=")" collection="list" item="item" index="index" separator="union all" >  
        select #{item.userId,jdbcType=INTEGER},#{item.username,jdbcType=VARCHAR},#{item.createDate,jdbcType=DATE}   
        from dual  
    </foreach>  
</insert> 

 

 

方式三

使用mybatisplus自帶的批量插入方法

IService.java
  /**
* 插入(批量) * * @param entityList 實體對象集合 * @param batchSize 插入批次數量 */ boolean saveBatch(Collection<T> entityList, int batchSize);

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM