MyBatis的基本使用

1.新增时,当违反唯一索引则修改对应字段的值

唯一索引

UNIQUE KEY `uniq` (`record_date`,`carrier_id`) USING BTREE

映射文件mapper.xml

<insert id="batchInsert" parameterType="java.util.List">
        insert into scs_carrier_distribution (
            record_date,
            carrier_id,
            carrier_name,
            total_count,
            success_count,
            failure_count,
            create_time,
            is_delete)
        values
        <foreach collection="list" item="item" separator=",">(
            #{item.recordDate},
            #{item.carrierId},
            #{item.carrierName},
            #{item.totalCount},
            #{item.successCount},
            #{item.failureCount},
            NOW(),
            #{item.isDelete})
        </foreach>
        on duplicate key update
        carrier_name = VALUES(carrier_name),
        total_count = VALUES(total_count),
        success_count = VALUES(success_count),
        failure_count = VALUES(failure_count),
        update_time = Now(),
        is_delete = VALUES(is_delete)
    </insert>

 

posted @ 2018-07-18 11:28  浪味仙人  阅读(142)  评论(0编辑  收藏  举报