MyBatis Data BULK Insert

Source: Internet
Author: User

First look at the batch Mapper.xml file

<insert id= "Insertbatch" parametertype= "java.util.List" >  <selectkey keyproperty= "Fetchtime" order= " Before "  resulttype=" java.lang.String ">  Select Current_timestamp ()  </selectKey>  Insert Into Kangaiduoyaodian (Depart1, Depart2, Product_Name,  generic_name, IMG, product_specification, Unit,  Approval_certificate, Manufacturer, Marketprice, Vipprice,  website, fetch_time, Productdesc) values  < foreach collection= "list" item= "item" index= "index"  separator= "," >  (#{item.depart1}, #{item.depart2}, # {item.productname},  #{item.genericname}, #{item.img},  #{item.productspecification}, #{item.unit},  #{item.approvalcertificate}, #{item.manufacturer},  #{item.marketprice}, #{item.vipprice}, #{ Item.website},  #{fetchtime}, #{item.productdesc})  </foreach>  </insert>

In the batch process, I found a few issues that need to be noted

1, the primary key of the automatic acquisition, add usegeneratedkeys= "true" keyproperty= "id" in insert is invalid, and or interrupt data insertion, if the ID is the database self-increment, you can write nothing, Remove the primary key attribute in the inserted statement, and use the

<selectkey keyproperty= "id" order= "before"  resulttype= "Java.lang.Integer" >  select last_insert_id ()  </selectKey>
Note :<selectkey > tags can only exist under the INSERT, the batch is not suitable for the use of <selectkey, the primary key self-increment is the best, or specify

2, insertion time acquisition as shown above, I use MySQL, as long as the MySQL function can be used to use, the insertion time and the primary key is one of the MySQL function ...



MyBatis I also in small try sledgehammer, if have improper place, please forgive me ....



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MyBatis Data 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.