# 广播表(公共表)

# 配置

指定广播表名称

# 公众表
spring.shardingsphere.sharding.broadcast‐tables=t_dict

# 测试

在插入修改或者删除,都会为每一个配置的数据源中公众表进行操作

mybatis.configuration.map-underscore-to-camel-case=true
spring.main.allow-bean-definition-overriding=true

#数据源名称

spring.shardingsphere.datasource.names=m1,m2

#连接池(上面名称叫啥这里就要写啥 m1 就写m1)
spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://localhost:3306/order_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=root

spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m2.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m2.url=jdbc:mysql://localhost:3306/order_db_2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
spring.shardingsphere.datasource.m2.username=root
spring.shardingsphere.datasource.m2.password=root

#数据分布情况,数据节点
#t_order可以任意,但是在SQL插入的时候就要跟这里对应
spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=m$->{1..2}.t_order_$->{1..2}

#指定t_order表的主键生成策略为SNOWFLAKE
spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id
spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE

# 分库配置
spring.shardingsphere.sharding.tables.t_order.database-strategy.inline.sharding-column=user_id
spring.shardingsphere.sharding.tables.t_order.database-strategy.inline.algorithm-expression=m$->{user_id % 2 + 1}


# 指定t_order表的分片策略,分片策略包括分片和分片算法
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.sharding-column=order_id
spring.shardingsphere.sharding.tables.t_order.table-strategy.inline.algorithm-expression=t_order_$->{order_id % 2 + 1}

# 公众表
spring.shardingsphere.sharding.broadcast‐tables=t_dict

mybatis.mapper-locations=classpath:mapper/*.xml

logging.level.root=info
logging.level.com.g.shardingjdbc=debug
logging.level.druid.sql=debug
logging.level.org.springframework.web=info


# 插入

在三个表中均有数据

int insert(@Param("type") String type, @Param("code") String code, @Param("value") String value);