oracle + mybatis 批量新增
mybatis 批量最大1000条,数据多的话,分多次执行批量操作:
javascript
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
javascript
List<List<Map<String, Object>>> partition = ListUtils.partition(list, 1000);
for (List<Map<String, Object>> maps : partition) {
taskMapper.insertBatchGmIntOrg(maps);
}
下面这种写法是本人测试多种批量插入写法,比较结果后得出执行最快的一种写法
javascript
<insert id="insertBatchGmIntOrg" parameterType="java.util.List">
INSERT INTO GM_INT_ORG (DATA_DT ,LP_ID ,ORG_ID)
<foreach collection="list" item="item" index="index" separator="union all">
select #{item.DATA_DT},#{item.LP_ID},#{item.ORG_ID} from dual
</foreach>
</insert>