Mybatis 中的insertOrUpdate操作

<insert id="insertOrUpdate">
 insert into base_person
       (pname, idcard, gender, nation, source_flag, create_time)
    values
    <foreach collection="list" item="p" index="index" separator=",">
        (#{p.pname},
        #{p.idcard},
        #{p.gender},
        #{p.nation},
        #{p.sourceFlag},
        #{p.createTime})
    </foreach>
    ON DUPLICATE KEY UPDATE
        pname=values(pname),
        idcard=values(idcard),
        gender=values(gender),
        nation=values(nation)
</insert>

相关推荐