用的是jeesite框架来批量插入数据
1.配置mapper文件
<insert id ="batchInsertList" parameterType="java.util.List">
INSERT INTO student_info(
seq,
name,
sender,
class_no,
enrolment_time
)
<foreach item = "item" index="index" collection="insertInfoList" separator="union all">
(select
#{item.seq} ,
#{item.name} ,
#{item.sender} ,
#{item.classNo, jdbcType=VARCHAR} ,<!--使用jdbctype来设置字段属性可以加快插入速度-->
to_char(#{item.enrolmentTime},'yyyy-MM-dd')<!--把日期格式变成字符串-->
from dual )
</foreach>
</insert>
2.在dao层添加方法
public void batchInsertList(@Param(“insertInfoList”) List insertTiList);
3.service层和controller正常调用就行了
注意:mysql和oracle批量插入的代码是不一样的,这个例子是用的oracle数据库,mysql可以参考这个:
https://blog.csdn.net/weixin_44369725/article/details/85624875