示例代碼:
1.dao層代碼:
int insertList(@Param("records") List<GwServerConfDetail> records);
2.xml層代碼:
<insert id="insertList" parameterType="java.util.List"> insert into gw_server_conf_detail ( SERVER_CONFIG_ID, CHANNEL_ID, NODE_NUM, SEND_ABILITY, CREATE_BY, UPDATE_BY) values <foreach collection="records" item="record" index="index" separator=","> ( #{record.serverConfigId}, #{record.channelId}, #{record.nodeNum}, #{record.sendAbility}, #{record.createBy}, #{record.updateBy} ) </foreach> on duplicate key update NODE_NUM=values(NODE_NUM), SEND_ABILITY=values(SEND_ABILITY), UPDATE_BY =values(UPDATE_BY) </insert>
注意:
on duplicate key update NODE_NUM=values(NODE_NUM),括號中的變量,應該與表中的字段名一致,而不是與類中的屬性名一致。