1、mybatis的版本必须为3.3.1及其以上数据库
项目所依赖的mybatis的版本必须为3.3.1及其以上,低版本的不行,保证hap项目的依赖的mybatis的jar的版本必需为须要的版本:mybatis
2、在Dao层不能使用@Param注解,且Mapper.xml文件中使用list变量接收Dao层中的集合app
数据库库结构设计:spa
对应的Dto层:设计
对应的Mapper接口:code
对应的Mapper.xml文件:server
具体代码以下,须要使用到mycat的注解,指定该插入为批量数据插入:xml
<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>
3、Mycat为分库表作全局序列的配置blog
schema.xml文件:接口
server.xml文件的全局序列方式设置为本地读取:
sequence_conf.properties文件的配置: