1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| # 配置数据源,数据源命名 spring.shardingsphere.datasource.names=m1
# 允许一个实体类对应两张表 spring.main.allow-bean-definition-overriding=true
# 配置数据源及连接池相关属性 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/test?serverTimezone=GMT%2B8 spring.shardingsphere.datasource.m1.username=root spring.shardingsphere.datasource.m1.password=qweasdzxc
# 指定user表分布情况,配置表在哪个数据库里面,表名称 m1.user_1 , m1.user_2 spring.shardingsphere.sharding.tables.user.actual-data-nodes=m1.user_$->{1..2}
# 指定user表里面主键uid 生成策略 SNOWFLAKE spring.shardingsphere.sharding.tables.user.key-generator.column=uid spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
# 指定分片策略,约定uid值偶数添加到user_1表,如果uid是奇数添加到user_2表 spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=uid spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{uid % 2 + 1}
# 打开sql输出日志 spring.shardingsphere.props.sql.show=true
|