BULK INSERT SQL statements:
INSERT into table (field1,field2,field3) VALUES (' A ', "B", "C"), (' A ', "B", "C"), (' A ', "B", "C")
The MyBatis SQL statements are assembled using the Foreach loop.
One, XML
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd ">3 <Mapper4 namespace= "Com.xxx.mapper.XXXRecordMapper">5 <ResultmapID= "Baseresultmap"type= "Com.xxx.model.XXXRecord">6 <IDcolumn= "Autoid" Property= "Autoid"Jdbctype= "BIGINT" />7 <resultcolumn= "UserId" Property= "userid"Jdbctype= "BIGINT" />8 <resultcolumn= "Noticedtime" Property= "Noticedtime"Jdbctype= "TIMESTAMP" />9 </Resultmap>Ten <SQLID= "Base_column_list"> One autoid, UserId, Noticedtime A </SQL> - <!--myself: Bulk Insert - - <InsertID= "Insertbatch"ParameterType= "Java.util.List"> the INSERT INTO T_xxxrecord (autoid, UserId, noticedtime) values - <foreachCollection= "List"Item= "Item"Index= "Index"Separator=","> - (#{item.autoid,jdbctype=bigint}, - #{item.userid,jdbctype=bigint}, + #{item.noticedtime,jdbctype=timestamp}) - </foreach> + </Insert> A </Mapper>
Description
- MySQL BULK insert limit is one batch: 1M
- I insert the list here, as above, if it is other structure, view this blog: http://www.cnblogs.com/admol/articles/4248159.html
- Collection Properties:
1. If a single parameter is passed in and the parameter type is a list, the collection property value is List
2. If a single parameter is passed in and the parameter type is an array, the value of the collection property is array
3. If the parameters passed in are multiple, we need to encapsulate them into a map, of course, the single parameter can also be encapsulated into a map
Fourth Chapter MyBatis BULK INSERT