mybatis批量插入和更新

批量插入

<insert id="add" parameterType="java.util.List">
insert all
<foreach item="item" index="index" collection="list" open="" separator="" close="">
into PARAMETETER_CONFIGURATION
( INPUT_NAME, WEIGTH_,MONTH_,ACTUAL_WORK)
values (#{item.inputName,jdbcType=DECIMAL},#{item.weigth,jdbcType=VARCHAR}, #{item.month,jdbcType=VARCHAR},#{item.actualWork,jdbcType=VARCHAR})
</foreach>
select 1 from dual
</insert>

批量更新

<!--批量更新 -->
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
UPDATE S_APPOINT
<set>
<if test="item.quitReasonNew != null and item.quitReasonNew!='' ">
QUIT_REASONNEW = #{item.quitReasonNew,jdbcType=VARCHAR},
</if>
<if test="item.quitTypeNew != null and item.quitTypeNew !='' ">
QUIT_TYPENEW = #{item.quitTypeNew,jdbcType=VARCHAR},
</if>
</set>
where APPOINT_NUMBER = #{item.appointNumber,jdbcType=VARCHAR}
</foreach>
</update>

原文地址:https://www.cnblogs.com/wcss/p/11914385.html