1 Star 4 Fork 1

xcc/sharding-jdbc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
application_2d2t.properties 2.58 KB
一键复制 编辑 原始数据 按行查看 历史
xcc 提交于 2021-01-24 23:39 +08:00 . 解决中文乱码
#多库多表 水平分库
server.port=56081
spring.application.name=sharding‐jdbc-demo
server.servlet.context‐path=/sharding‐jdbc-demo
#编码
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
spring.http.encoding.force=true
spring.main.allow-bean-definition-overriding=true
#将数据库的_字段自动映射为驼峰
mybatis.configuration.map-underscore-to-camel-case=true
# 打开sql输出日志
spring.shardingsphere.props.sql.show=true
swagger.enable=true
#log日志配置
logging.level.root=info
logging.level.org.springframework.web=info
logging.level.com.xcc.dbsharding=debug
logging.level.druid.sql=debug
#sharding-jdbc分片规则配置
#数据源
spring.shardingsphere.datasource.names=m1,m2
#数据源m1 连接order_db_1数据库
spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource&characterEncoding=utf8
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m1.url=jdbc:mysql://hadoop102:3306/order_db_1?useUnicode=true
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=123456
#数据源m2 连接order_db_2数据库
spring.shardingsphere.datasource.m2.type=com.alibaba.druid.pool.DruidDataSource&characterEncoding=utf8
spring.shardingsphere.datasource.m2.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.m2.url=jdbc:mysql://hadoop102:3306/order_db_2?useUnicode=true
spring.shardingsphere.datasource.m2.username=root
spring.shardingsphere.datasource.m2.password=123456
# 分库策略,以user_id为分片键,分片策略为user_id % 2 + 1,user_id为偶数操作m1数据源,否则操作m2。
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表的数据分布情况,配置数据节点 m1.t_order_1,m1.t_order_2,m2.t_order_1,m2.t_order_2
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
# 指定t_order表的分片策略,分片策略包括分片键(order_id)和分片算法(t_order_$->{order_id % 2 + 1})
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}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/xiaocheng0902/sharding-jdbc.git
git@gitee.com:xiaocheng0902/sharding-jdbc.git
xiaocheng0902
sharding-jdbc
sharding-jdbc
master

搜索帮助