public void saveBatchData(List<Student> list) {
int len = 0;
if(CollectionUtils.isNotEmpty(list)){
if(list.size()%400 == 0){
len = list.size()/200;
}else{
len = list.size()/200+1;
}
}
for(int i=0;i<len;i++) {
List<Student> lists = new ArrayList<>();
int max = 200 * (i + 1);
if (i == len - 1) {
max = list.size();
}
for (int j =200 * i; j < max; j++) {
Student stu = list.get(j);
stu.setDeletedFlag(0);
lists.add(stu);
}
studentDao.saveData(lists);
}
}
<insert id="saveData" parameterType="java.util.List">
INSERT INTO sys_student(
name,
created_staffId,
created_time,
modified_staffId,
modified_time,
deleted_flag
)VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.name},
#{item.createdStaffId},
#{item.createdTime},
#{item.modifiedStaffId},
#{item.modifiedTime},
#{item.deletedFlag})
</foreach>
</insert>
<update id="updateData" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator=";">
UPDATE sys_student SET
name = #{item.name},
modified_staffId = #{item.modifiedStaffId},
modified_time = #{item.modifiedTime}
WHERE id = #{item.id}
</foreach>
</update>