在mybaits中使用insert into xx values(xxx) on duplicate key update
前提是数据库数据表设置唯一主键:
dao层:
public void batchAddOperateTaskTotal(@Param("operateTaskStatisticsList") ListoperateTaskStatisticsList);//工单数据按天批量入库
mapper的配置:
insert into daily_operatetask_statistics (search_day,company_id,operate_area_id,exchage_count,back_count,
check_count,dispatch_count,find_count,no_use2days_count,no_use5days_count,time_type,create_time,update_time
)
values
(
#{item.searchDay,jdbcType=DATE},
#{item.companyId,jdbcType=INTEGER}, #{item.operateAreaId,jdbcType=INTEGER}, #{item.exchageCount,jdbcType=INTEGER},
#{item.backCount,jdbcType=INTEGER}, #{item.checkCount,jdbcType=INTEGER},#{item.dispatchCount,jdbcType=INTEGER},
#{item.findCount,jdbcType=INTEGER},#{item.noUse2DaysCount,jdbcType=INTEGER},#{item.noUse5DaysCount,jdbcType=INTEGER},
#{item.TimeType,jdbcType=INTEGER}, now(),now()
)
on duplicate key update
search_day=values(search_day),company_id=values(company_id),operate_area_id=values(operate_area_id),
exchage_count=values(exchage_count),back_count= values(back_count),check_count=values(check_count),
dispatch_count=values(dispatch_count),find_count=values(find_count),no_use2days_count=values(no_use2days_count),
no_use5days_count=values(no_use5days_count),time_type=values(time_type),update_time=now()
注意:on duplicate key update 后面的数据表字段的赋值values()里面也是数据表字段,并不是前端字段。