示例代码:
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),括号中的变量,应该与表中的字段名一致,而不是与类中的属性名一致。