Problem solving: Mycat database middleware +mybatis BULK INSERT data and return all primary key IDs for Row Records

Source: Internet
Author: User
Tags bulk insert

First, the MyBatis version must be 3.3.1 and above

The version of the MyBatis that the project relies on must be 3.3.1 and above, the lower version is not, and the version of the jar that ensures that the dependent mybatis of the HAP project needs to be the required version:

Second, @param annotations cannot be used in the DAO layer, and the list variable is used in the Mapper.xml file to receive collections in the DAO layer

Database Library structure Design:

The corresponding DTO layer:

The corresponding Mapper interface:

The corresponding Mapper.xml file:

The specific code below requires the use of annotations to Mycat, which specifies that the insert is for bulk data insertion:

<insert id= "Insertbybatch" >
/*!mycat:catlet=io.mycat.route.sequence.batchinsertsequence * *
Insert into Test_sharding_by_accounting_date (rule_code,name,accounting_date)
Values
<foreach collection= "List" item= "item" index= "index" separator= "," >
(#{item.rulecode,jdbctype=decimal},#{item.name,jdbctype=varchar},#{item.accountingdate,jdbctype=date})
</foreach>
</insert>

Third, Mycat for the Sub-Library table to do the global sequence configuration

Schema.xml file:

The global sequence of the Server.xml file is set to read locally:

Configuration of the Sequence_conf.properties file:

Problem solving: Mycat database middleware +mybatis BULK INSERT data and return all primary key IDs for Row Records

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.