部分已驗證环疼,稍后完善
1、插入
(1)第一種方式:利用<foreach>標(biāo)簽朵耕,將入?yún)⒌膌ist集合通過UNION ALL生成虛擬數(shù)據(jù)炫隶,從而實現(xiàn)批量插入
<insert id="insertBatchLaTContactRecord" parameterType="java.util.Map">
<selectKey resultType="java.lang.Long" keyProperty="dto.id" order="BEFORE">
select seq_LA_T_CONTACT_RECORD.nextval as id from dual
</selectKey>
insert into la_t_contact_record
(
id,
contract_id,
contacter_add_name,
contacter_add_type,
contact_add_phone,
contact_add_home_address,
contact_add_work,
contact_add_work_address,
create_by,
create_time ,
modify_by,
modify_time,
validate_state,
sys_source,
isquery
)
select seq_LA_T_CONTACT_RECORD.NEXTVAL,A.* from(
<foreach collection="list" item="dto" index="index" separator="UNION ALL">
select
#{dto.contractId,jdbcType=VARCHAR}
,#{dto.contacterAddName,jdbcType=VARCHAR}
,#{dto.contacterAddType,jdbcType=VARCHAR}
,#{dto.contactAddPhone,jdbcType=VARCHAR}
,#{dto.contactAddHomeAddress,jdbcType=VARCHAR}
,#{dto.contactAddWork,jdbcType=VARCHAR}
,#{dto.contactAddWorkAddress,jdbcType=VARCHAR}
,#{dto.createBy,jdbcType=DECIMAL}
,systimestamp
,#{dto.modifyBy,jdbcType=DECIMAL}
,#{dto.modifyTime,jdbcType=TIMESTAMP}
,'1'
,#{dto.sysSource,jdbcType=VARCHAR}
,#{dto.isquery,jdbcType=VARCHAR}
from dual
</foreach>) A
</insert>
注意:入?yún)⒈仨毷莑ist集合,sql語句中沒有values阎曹;
(2)第二種方式:利用存儲過程實現(xiàn)批量插入
<insert id="insertPlanRepaymentOtherfeeBatch" parameterType="java.util.List">
begin
<foreach collection="list" item="item" index="index">
insert into lb_t_plan_repayment_otherfee
(
id,
key,
value,
term ,
contract_id,
PAY_ORDER,
FEE_NAME,
INTO_ID
)
values(SEQ_LB_T_PLAN_REPAY_OTHERFEE.nextval
,#{item.key,jdbcType=VARCHAR}
,#{item.value,jdbcType=VARCHAR}
,#{item.term,jdbcType=DECIMAL}
,#{item.contractId,jdbcType=VARCHAR}
,#{item.payOrder,jdbcType=DECIMAL}
,#{item.feeName,jdbcType=VARCHAR}
,#{item.intoId,jdbcType=VARCHAR}
);
</foreach>
end;
</insert>
注意:入?yún)⑷匀皇莑ist集合伪阶,sql中有values煞檩,本質(zhì)是利用存儲過程實現(xiàn)批量插入;
2望门、更新
(1)第一種方式:同樣是利用存儲過程
<update id="batchUpdateUser" parameterType="java.util.ArrayList">
<foreach collection="list" item="userlist" index="index" open="begin" close=";end;" separator=";">
UPDATE USERINFO T
<set>
T.USERID = #{userlist.userid,jdbcType=VARCHAR},
T.USERNAME = #{userlist.username,jdbcType=VARCHAR},
</set>
WHERE
T.USERID = #{userlist.userid,jdbcType=VARCHAR}
</foreach>
</update>
(2)第二種方式:利用條件實現(xiàn)
<update id="updateBatchByListStat" parameterType="java.util.Map">
update la_t_advfinished t1
set t1.list_stat='07',
t1.modify_time =systimestamp
where t1.id in(<foreach collection="ids" separator="," item="id">'${id}'</foreach>)
</update>
注意:同樣可以使用or的條件實現(xiàn)形娇,類似于下面刪除的sql锰霜;
3筹误、刪除
與更新第二種方式類似
<delete id="deleteAttractions" parameterType="java.util.List">
delete from ATTRACTIONS
<where>
<foreach collection="list" index="index" item="item" open="(" separator="or" close=")">
id=#{item.id}
</foreach>
</where>
</delete>