mybatis批量插入 批量更新
批量插入
<insert id="insertBatch" parameterType="java.util.List"> insert into xg_t_ss_rc_wj( wid, fsrq, insert_time, last_changed, status ) values <foreach collection="list" item="item" index="index" separator=","> ( #{item.wid}, #{item.fsrq}, now(), now(), 1 ) </foreach> </insert>
mapper中
void insertBatch(ArrayList<XgTSsRcWjInfo> list);
最近写批量插入的时候,遇到唯一约束,想要实现如果已经存在就更新。
详细介绍请看:https://blog.csdn.net/qq_42269354/article/details/100589640
<insert id="insertBatch"> insert into sys_hospital_project_relation (hospital_id, project_id, quantity ) values <foreach collection="hospitalProjectRelations" separator="," item="bi"> ( #{bi.hospitalId}, #{bi.projectId}, #{bi.quantity} ) </foreach> ON DUPLICATE KEY UPDATE hospital_id=VALUES(hospital_id),project_id=VALUES(project_id),quantity=VALUES(quantity) </insert>