mybatis基于唯一索引插入或更新

<insert id="insertBatchOrUpdate">
    INSERT INTO t_homework_day_detail(m_id,stu_id,homewk_id,homewk_name,category_name,
    complete_status,score,create_time,end_time,
    course_id,course_name,org_id,tch_id,update_time,
    tch_name,course_unit_id,textbook_id,textbook_version_id,textLevel_id,add_time,check_time)
    VALUES
    <foreach collection="studentHomeList" item="entity" separator=",">
        (#{entity.id},#{entity.stuId},#{entity.homewkId},#{entity.homewkName},#{entity.categoryName},
        #{entity.completeStatus},#{entity.score},#{entity.createTime},#{entity.endTime},
        #{entity.courseId},#{entity.courseName},#{entity.orgId},#{entity.tchId},#{entity.updateTime},
        #{entity.tchName},#{entity.courseUnitId},#{entity.textbookId},#{entity.textbookVersionId},
        #{entity.textLevelId}, #{entity.addTime},#{entity.checkTime})
    </foreach>
        ON DUPLICATE KEY UPDATE
        complete_status=values(complete_status),score=values(score),
        update_time=values(update_time),end_time=values(end_time)
</insert>
posted @ 2020-08-09 11:46  韩小韩Sunny  阅读(2691)  评论(0编辑  收藏  举报