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计算逻辑改变导致找不到表了

你可能感兴趣的:(工具类,中间件)