Fourth Chapter MyBatis BULK INSERT

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.