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文件的配置: