不多BB直接上代码
JAVA
//要插入的list
List<Item> list = new ArrayList<>();
int len = 1000;
int size = list.size();
int count = (size + len - 1) / len;
for (int i = 0; i < count; i++) {
List<Item> subListOK =
list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
this.baseMapper.batchSave(subListOK);
}
Mapper
<insert id="batchSave" parameterType="java.util.List">
INSERT INTO 表名 (
ID,
CR_DT ) VALUES
<foreach collection="list" item="entity" separator=",">
(
#{entity.id},
#{entity.crDt}
)
</foreach>
</insert>