MyBatis
BULK INSERT
Int Addbatch (@Param ("list") list<custinfo> list);
<insert id= "Addbatch" parametertype= "Java.util.List" >
INSERT into CUSTINFO (
Serialid,
CUSTID,
INVNM,
Updatetimestamp
)
<foreach collection= "List" item= "Item" separator= "union All" index= "index" >
(SELECT
#{item.serialid, Jdbctype=varchar},
#{item.custid, Jdbctype=varchar},
#{item.invnm, Jdbctype=varchar},
To_timestamp (#{item.updatetimestamp}, ' Syyyy-mm-dd hh24:mi:ss.ff ')
From DUAL
)
</foreach>
</insert>
Bulk Delete
int Delcustinfobatch (@Param ("list") list<custinfo> list);
<update id= "Delcustinfobatch" parametertype= "Java.util.List" >
DELETE from CUSTINFO
WHERE Serialid in
<foreach collection= "List" item= "Item" open= "(" separator= "," close= ")" index= "index" >
#{item.serialid,jdbctype=varchar}
</foreach>
</update>
To do a bulk INSERT database, you first need to know the syntax that the database supports for bulk INSERT. The syntax for bulk inserts for each database is different.
MySQL Insertion
<insert id= "BatchSave" parametertype= "Java.util.List" >
INSERT into table_name
( Id
NAME
)
VALUES
<foreach collection= "List" item= "item" separator= "," >
( #{item.id,jdbctype=varchar},
#{item.name,jdbctype=varchar}
)
</foreach>
</insert>
MyBatis BULK INSERT, bulk delete