mybatis 當需要批量插入並更新主鍵相同的資料時的處理方法
阿新 • • 發佈:2018-12-04
該方法 如果表中沒有沒有主鍵對應的資料就新增一條 如果有的話就更新該條資料
<insert id="insertBatch"> REPLACE into representatives_and_principal_personnel (id,examine_and_approve_id, idcard_number, name, sex, duty, rankv, birth, standard_culture, workspace, state, phone, have_bad_record, amount_of_contribution) values <foreach collection="list" item="representativesAndPrincipalPersonnel" separator=","> (#{representativesAndPrincipalPersonnel.id}, #{representativesAndPrincipalPersonnel.examine_and_approve_id}, #{representativesAndPrincipalPersonnel.idcard_number}, #{representativesAndPrincipalPersonnel.name}, #{representativesAndPrincipalPersonnel.sex}, #{representativesAndPrincipalPersonnel.duty}, #{representativesAndPrincipalPersonnel.rankv}, #{representativesAndPrincipalPersonnel.birth}, #{representativesAndPrincipalPersonnel.standard_culture}, #{representativesAndPrincipalPersonnel.workspace}, #{representativesAndPrincipalPersonnel.state}, #{representativesAndPrincipalPersonnel.phone}, #{representativesAndPrincipalPersonnel.have_bad_record}, #{representativesAndPrincipalPersonnel.amount_of_contribution}) </foreach> </insert>