前言
trader_users_fee_result表没有主键,没有唯一索引,唯一的一个要求是:
user_id,ename,Date三个字段 在没条记录里唯一,即不能有2条记录,每一条记录的这三个字段都相同。
将这3个字段做一个联合索引:
alter table trader_users_fee_result add index ‘unionIndex’(‘user_id’,‘ename’,‘Date’);
这样后面在replace into时,mysql才能判断新的带插入的数据是否在表里已存在。
原始数据类型
待插入的list的数据如下:
List<TraderUserFeeResultBean> beanList;
Mapper接口里的方法:
/**
* 批量更新用户费率表 trader_users_fee_result表
* @param bean
*/
void insertUserByBeans(List<TraderUserFeeResultBean> bean);
xml里的sql写法
replace into trader_users_fee_result ( user_id,ename,month, first_level_organization_commission,second_level_organization_commission, third_level_organization_commission,fourth_level_organization_commission, first_level_organization_settle_fee,second_level_organization_settle_fee, third_level_organization_settle_fee,fourth_level_organization_settle_fee ) values ( #{item.user_id},#{item.ename},#{item.month}, #{item.first_level_organization_commission},#{item.second_level_organization_commission}, #{item.third_level_organization_commission},#{item.fourth_level_organization_commission}, #{item.first_level_organization_settle_fee},#{item.second_level_organization_settle_fee}, #{item.third_level_organization_settle_fee},#{item.fourth_level_organization_settle_fee} )
在foreach里,每个item就是一个bean对象,可以通过对象.属性的方式获取值,index=“index”里的index标识list集合的下标值。