1、循环插入(10条496ms 100条3330ms 500条15584ms 1000条33755ms)
studentList.stream().forEach(student -> studentMapper.insert(student));
2、foreach标签(10条268ms 100条366ms 500条392ms 1000条648ms)
<insert id="insert" parameterType="Student">
INSERT INTO tb_student (name, age, phone, address, class_id) VALUES (#{name},#{age},#{phone},#{address},#{classId})
</insert>
<insert id="insertBatch">
INSERT INTO tb_student (name, age, phone, address, class_id) VALUES
<foreach collection="list" separator="," item="item">
(#{item.name},#{item.age},#{item.phone},#{item.address},#{item.classId})
</foreach>
</insert>
3、批处理(10条222ms 100条244ms 500条364ms 1000条426ms)
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
StudentMapper studentMapperNew = sqlSession.getMapper(StudentMapper.class);
studentList.stream().forEach(student -> studentMapperNew.insert(student));
sqlSession.commit();
sqlSession.clearCache();
版权声明:本文为qq_42615006原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。