mybatis批量插入

 
  1.     
    1.      <!-- 批量插入Mysql -->
              <insert id="batchInsert" parameterType="java.util.List">
                  insert into b_agent_info
                  (id,hkgs,userName,custName,office,remark) values
                  <foreach collection="list" item="item" index="index"
                      separator=",">
                      (#{item.id},#{item.hkgs},#{item.userName},#{item.custName},#{item.office},#{item.remark})
                  </foreach>
              </insert> 

    2.      <!-- 批量插入Oracle -->
      
          <insert id="batchInsert" parameterType="ArrayList">
          insert into xxxxtable(hkgs,hkgsjsda,office,asdf,ddd,ffff,supfullName,classtype,agent_type,remark)
          <foreach collection="list" item="item" index="index" separator="union all">
          select #{item.hkgs,jdbcType=VARCHAR},
          #{item.hkgsjsda,jdbcType=VARCHAR},
          #{item.office,jdbcType=VARCHAR},
          #{item.asdf,jdbcType=VARCHAR},
          #{item.ddd,jdbcType=VARCHAR},
          #{item.ffff,jdbcType=VARCHAR},
          #{item.supfullName,jdbcType=VARCHAR},0,0,
          #{item.remark,jdbcType=VARCHAR} from dual
          </foreach>
          </insert>

你可能感兴趣的:(mybatis)