1.批量插入
<insert id="insertNumber" parameterType="java.util.List" useGeneratedKeys="false">
insert into ZX_APP_PD_PANDIAN(GOODSID,LOTNO,REALQTY,CUTID)
<foreach collection="list" item="item" index="index" separator="union all" >
(select
#{item.goodsid}, #{item.lotno,jdbcType=VARCHAR}, #{item.realqty,jdbcType=NUMERIC},#{item.cutid}
from dual)
</foreach>
</insert>
<insert id="insertBatch" parameterType="java.util.List">
INSERT INTO T_CITY_INDEX( id,city_code )
select SEQ_CITY_INDEX.NEXTVAL,cd.* from(
<foreach collection="list" item="item" index="index" close=")" open="(" separator="union">
select
#{item.cityCode,jdbcType=VARCHAR},
#{item.cityName,jdbcType=VARCHAR}
from dual
</foreach>
) cd
</insert>
2.批量更新
<update id="checkData" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
update zx_app_checkqty_tmp t
set t.checkqty=#{item.checkqty},t.LASTUPDATETIME=sysdate,t.flag=1
where t.placesupplyno=#{item.supplyno} and t.placepointid=#{item.deptid}
and t.goodsdid=#{item.goodsid} and t.lotno=#{item.lotno,jdbcType=VARCHAR}
</foreach>
</update>
3.使用oracle的序列号
<insert id="addUser" parameterType="user" >
<!-- keyProperty: 将序列号设置到user对象中,且在controller中可以使用 -->
<selectKey keyProperty="id" order="BEFORE" resultType="string">
SELECT seq_changez_user.nextval id from dual
</selectKey>
insert into temp_changez_user (id, username) values(#{id}, #{username})
</insert>