sharding-jdbc介绍

ShardingSphere简介
数据分片、分布式事务、读写分离、数据迁移、跨源的数据关联与聚合、数据加密

#shardingjdbc用于分库分表配置
#一个实体类对应两张表,覆盖

#shardingjdbc分片策略
#配置数据源,给数据源起名称,#水平分库,配置两个数据源
spring.shardingsphere.datasource.names = datasource_name_1

#配置第一个数据源具体内容,包含连接池,驱动,地址,用户名和密码
spring.shardingsphere.datasource.datasource_name_1.type = #连接池
spring.shardingsphere.datasource.datasource_name_1.driver-class-name = #驱动
spring.shardingsphere.datasource.datasource_name_1.url = 
spring.shardingsphere.datasource.datasource_name_1.username = 
spring.shardingsphere.datasource.datasource_name_1.password = 

#指定数据库分布情况,数据库里面表分布情况
spring.shardingsphere.sharding.tables.user_info.actual-data-nodes = datasource_name_1.user_info_$->{1..8}

#指定user_contact_info表里面主键id生成策略SNOWFLAKE
spring.shardingsphere.sharding.tables.user_info.key-generator.column = id
spring.shardingsphere.sharding.tables.user_info.key-generator.type = SNOWFLAKE

#指定表分片策略
#行表达式分片策略
#spring.shardingsphere.sharding.tables.user_info.table-strategy.inline.sharding-column = cust_no
#spring.shardingsphere.sharding.tables.user_info.table-strategy.inline.algorithm-expression = user_info_$->{Math.abs(cust_no.hashCode()) % 8 + 1}

#自定义策略
spring.shardingsphere.sharding.tables.user_info.table-strategy.standard.sharding-column = cust_no
spring.shardingsphere.sharding.tables.user_info.table-strategy.standard.precise-algorithm-class-name = com.paic.ph.cjm.configuration.MyTablePreciseShardingAlgorithm

MyTablePreciseShardingAlgorithm其实可以不需要,之前考虑自己实现hashcode是防止更换jdk后hashcode计算逻辑改变导致找不到表了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值