insert into seibertron_orgdatasyn.taxsource_submit_result(id,submitTaxSourceId, submitObjType, submitObjId,submitObjGroupId, externalPrimaryKey, status, remark, createdTime, createdUserId, riskStatus, riskStatusName) values () # <foreach collection="list" item="entity" separator=","> # (#{entity.id},#{entity.submitTaxSourceId}, #{entity.submitObjType}, #{entity.submitObjId},#{entity.submitObjGroupId}, #{entity.externalPrimaryKey}, # #{entity.status}, #{entity.remark}, now(), #{entity.createdUserId}, #{entity.riskStatus}, # #{entity.riskStatusName}) # </foreach> on duplicate key update status = values(status) , externalPrimaryKey = case values(externalPrimaryKey) when '-1' then externalPrimaryKey else values(externalPrimaryKey) end, remark =values(remark) , riskStatus = values(riskStatus) , riskStatusName = values(riskStatusName),createdTime = now()
1. 解决的问题,在批量插入或者更新中,更新需要配合业务条件,当部分数据需要更新,部分则需要保持原来数据
2. 思考:由于是批量插入或者更新,无法配合mybatis的标签使用条件更新
3. 解决方案:配合case when解决;values(externalPrimaryKey)参数,externalPrimaryKey数据库中的值。