My interface definition:
int Insertabilitypackageconsumer (Abilitypackageconsumer abilitypackageconsumer);
My entry entity length is this: (To reduce the amount of code, I only put the attribute)
public class Abilitypackageconsumer implements serializable{
/**
* */
private static final long Serialversionuid = 7922942036926940889L;
Private long appid;//Application ID private long
abilitypackageid;//capability package ID
private long abilityid;//capability ID
Private Long abilityruleid;//ability fee rule ID
private long chargeruleid;//billing policy ID
private Date subscribetime;//order time
Private Long crtuid;//creator
private Date crttime;//creation time
Private list<abilitydetail> abilitylist;
}
So what should be written about MyBatis's BULK INSERT statement?
That's what I wrote in the mapping file:
<insert id= "Insertabilitypackageconsumer" >
insert INTO Ability_package_consumer (App_id,ability_package_ id,ability_id,
ability_rule_id,charge_rule_id,subscribe_time,crt_uid,crt_time)
Select A.* from
(
<foreach collection= "abilitylist" item= "ability" index= "index" separator= "UNION" >
SELECT
#{appid,jdbctype=bigint} as app_id,
#{abilitypackageid,jdbctype=bigint} as ability_package_id,
#{ability.abilityid,jdbctype=bigint} as ability_id,
#{ability.abilityruleid,jdbctype=bigint} as Ability_rule_ ID,
#{ability.chargeruleid,jdbctype=bigint} as charge_rule_id, now
() as Subscribe_time,
#{crtuid, Jdbctype=bigint} as Crt_uid, now
() as Crt_time from
dual
</foreach>
) A
</insert >
Through a foreach traversal, a combined view of multiple records is completed, collection attribute values are consistent with the entity, item is customized, and then passed. accesses its property values.
This is primarily based on the INSERT into table name (?,?,?) in SQL (?,?,?) Union (?,?,?) The use of this statement, after the table name. Represents a field name, followed by a property value.