栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Sharding-JDBC笔记01-SpringBoot2.5+MybatisPlus+Sharding-Jdbc项⽬创建

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Sharding-JDBC笔记01-SpringBoot2.5+MybatisPlus+Sharding-Jdbc项⽬创建

1.pom文件

  
        
        1.8
        1.8
        1.8
        2.5.5
        3.4.0
        1.18.16
        4.1.1
        4.12
        1.1.16
        
        true
    

    
        
            org.springframework.boot
            spring-boot-starter-web
            ${spring.boot.version}
        
        
            org.springframework.boot
            spring-boot-starter-test
            ${spring.boot.version}
            test
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            ${mybatisplus.boot.starter.version}
        
        
            mysql
            mysql-connector-java
            8.0.27
        
        
            org.projectlombok
            lombok
            ${lombok.version}
        
        
            org.apache.shardingsphere
            sharding-jdbc-spring-boot-starter
            ${sharding-jdbc.version}
        
        
            junit
            junit
            ${junit.version}
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                ${spring.boot.version}
                
                    true
                    true
                
            
        
    

2.application.properties文件

server.port=8080
spring.application.name=xdclass-jdbc
logging.level.root=INFO
# 打印执⾏的数据库以及语句
spring.shardingsphere.props.sql.show=true
# 数据源 db0
spring.shardingsphere.datasource.names=ds0
# 第⼀个数据库
spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://127.0.0.1:3306/shardingjdbc_0?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
spring.shardingsphere.datasource.ds0.username=root
spring.shardingsphere.datasource.ds0.password=root
# 指定product_order表的数据分布情况,配置数据节点,⾏表达式标识符使⽤ ${...} 或 $->{...},但前者与 Spring 本身的⽂件占位符冲突,所以在 Spring 环境中建议使⽤ $->{...}
spring.shardingsphere.sharding.tables.product_order.actual-data-nodes=ds0.product_order_$->{0..1}
# 指定product_order表的分⽚策略,分⽚策略包括【分⽚键和分⽚算法】
spring.shardingsphere.sharding.tables.product_order.table-strategy.inline.sharding-column=user_id
spring.shardingsphere.sharding.tables.product_order.table-strategy.inline.algorithm-expression=product_order_$->{user_id % 2}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/781274.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号