以下是批量插入的demo 大家可以参考,也算我爬过的坑
--- 带序列主键的批量插入
<insert id="addCheckDetail" parameterType="java.util.List">
INSERT INTO CHECK_DETAIL(
CHECK_id,CHECK_DATE,CHECK_WEEK,EMP_CODE,CHECK_TIME,CHECK_LATE,CHECK_LEAVE_EARLY,
CHECK_EXCEPTION,CHECK_WORK_OVERTIME,EMP_NAME,DEPT_NAME,CHECK_LATE_TIME,DESCRIPTION
)
select CHECK_DETAIL_SEQ.NEXTVAL,cd.* from(
<foreach collection="list" item="item" index="index" separator="union all">
select
#{item.checkDate,jdbcType=VARCHAR},
#{item.checkWeek,jdbcType=VARCHAR},
#{item.empCode,jdbcType=VARCHAR},
#{item.checkTime,jdbcType=VARCHAR},
#{item.checkLate,jdbcType=VARCHAR},
#{item.checkLeaveEarly,jdbcType=VARCHAR},
#{item.checkException,jdbcType=VARCHAR},
#{item.checkWorkOverTime,jdbcType=VARCHAR},
#{item.empName,jdbcType=VARCHAR},
#{item.deptName,jdbcType=VARCHAR},
#{item.checkLateTime,jdbcType=VARCHAR},
#{item.description,jdbcType=VARCHAR}
from dual
</foreach>
) cd
</insert>
--- 不带序列主键的批量插入
<insert id="addCheckDetail" parameterType="java.util.List">
INSERT INTO CHECK_DETAIL(
CHECK_id,CHECK_DATE,CHECK_WEEK,EMP_CODE,CHECK_TIME,CHECK_LATE,CHECK_LEAVE_EARLY,
CHECK_EXCEPTION,CHECK_WORK_OVERTIME,EMP_NAME,DEPT_NAME,CHECK_LATE_TIME,DESCRIPTION
)
<foreach collection="list" item="item" index="index" separator="union all">
select
#{item.checkId,jdbcType=VARCHAR},
#{item.checkDate,jdbcType=VARCHAR},
#{item.checkWeek,jdbcType=VARCHAR},
#{item.empCode,jdbcType=VARCHAR},
#{item.checkTime,jdbcType=VARCHAR},
#{item.checkLate,jdbcType=VARCHAR},
#{item.checkLeaveEarly,jdbcType=VARCHAR},
#{item.checkException,jdbcType=VARCHAR},
#{item.checkWorkOverTime,jdbcType=VARCHAR},
#{item.empName,jdbcType=VARCHAR},
#{item.deptName,jdbcType=VARCHAR},
#{item.checkLateTime,jdbcType=VARCHAR},
#{item.description,jdbcType=VARCHAR}
from dual
</foreach>
</insert>