<insert id="insertEmpSelectiveBatch" parameterType="java.util.List" >
begin
<foreach collection="list" item="item" index="index" separator=";" >
insert into EMP
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="item.empno != null">
EMPNO,
</if>
<if test="item.ename != null">
ENAME,
</if>
<if test="item.job != null">
JOB,
</if>
<if test="item.mgr != null">
MGR,
</if>
<if test="item.hiredate != null">
HIREDATE,
</if>
<if test="item.sal != null">
SAL,
</if>
<if test="item.comm != null">
COMM,
</if>
<if test="item.deptno != null">
DEPTNO,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="item.empno != null">
#{item.empno,jdbcType=DECIMAL},
</if>
<if test="item.ename != null">
#{item.ename,jdbcType=VARCHAR},
</if>
<if test="item.job != null">
#{item.job,jdbcType=VARCHAR},
</if>
<if test="item.mgr != null">
#{item.mgr,jdbcType=DECIMAL},
</if>
<if test="item.hiredate != null">
#{item.hiredate,jdbcType=TIMESTAMP},
</if>
<if test="item.sal != null">
#{item.sal,jdbcType=DECIMAL},
</if>
<if test="item.comm != null">
#{item.comm,jdbcType=DECIMAL},
</if>
<if test="item.deptno != null">
#{item.deptno,jdbcType=DECIMAL},
</if>
</trim>
</foreach>
;commit;end;
</insert>
Mybatis之批量插入
批量插入EMP记录
最新推荐文章于 2025-11-26 15:59:01 发布
本文介绍了一种使用MyBatis框架进行EMP表数据批量插入的方法。通过<insert>标签结合<foreach>循环遍历List集合,实现了对EMP表的EMPNO, ENAME等字段的按需插入。每条插入语句会根据提供的对象属性是否存在来决定是否插入相应的字段及值。
549

被折叠的 条评论
为什么被折叠?



