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