mybatis提供了批量上传的方法,其实只需要在xml中配置sql语句即可,我们直接来看实现:
<insert id="insertlist" parameterType="java.util.List">
insert into rfid_raw_eri (tid, bzhh, bzxh)
<foreach collection="list" item="bean" index="index" separator="union all">
( select #{bean.tid,jdbcType=VARCHAR},
#{bean.bzhh,jdbcType=VARCHAR},
#{bean.bzxh,jdbcType=VARCHAR} from dual)
/foreach>
</insert>
如果需要oracle的sequence自动生成主键的话,需要稍作改动,实现如下:
<insert id="insertlist" parameterType="java.util.List"> insert into rfid_raw_eri_inventory (xh, bzhh, bzxh, rkdh, zt) SELECT SEQ_TEST.NEXTVAL, A.* FROM( <foreach collection="list" item="bean" index="index" separator="union all"> ( select #{bean.bzhh,jdbcType=VARCHAR}, #{bean.bzxh,jdbcType=VARCHAR}, #{bean.rkdh,jdbcType=VARCHAR}, 1 from dual) </foreach> ) A </insert>
转载于:https://blog.51cto.com/xuepiaoqiyue/1715338