-- 单条
<insert id="InsertOrUpdate_Info" parameterType="net.sahv.sssmiao.model.MemberInteraction">
insert into member_interaction (mi_id,mi_m_id, mi_sys_id,
mi_mac, mi_endtime, mi_state
)
values (#{miId},#{info.miMId}, #{miSysId},#{miMac}, #{miEndtime}, #{miState})
ON DUPLICATE KEY UPDATE
mi_m_id = VALUES(mi_m_id),
mi_sys_id = VALUES(mi_sys_id),
mi_mac = VALUES(mi_mac),
mi_endtime = VALUES(mi_endtime),
mi_state = VALUES(mi_state)
</insert>
-- 批量
<insert id="InsertOrUpdate_Info" parameterType="net.sahv.sssmiao.model.MemberInteraction">
insert into member_interaction (mi_id,mi_m_id, mi_sys_id,
mi_mac, mi_endtime, mi_state
)
values
<foreach collection ="list" item="info" separator="," >
(#{info.miId},#{info.miMId}, #{info.miSysId},#{info.miMac}, #{info.miEndtime}, #{info.miState}
)
</foreach>
ON DUPLICATE KEY UPDATE
mi_m_id = VALUES(mi_m_id),
mi_sys_id = VALUES(mi_sys_id),
mi_mac = VALUES(mi_mac),
mi_endtime = VALUES(mi_endtime),
mi_state = VALUES(mi_state)
</insert>
特别说明
ON DUPLICATE KEY UPDATE
info_price = values(info_price),created_at=values(created_at)
values(***) 是指 如果数据库表中已存在新插入的这条数据 将这条旧数据的info_price更新为valuse中的数据