zoukankan      html  css  js  c++  java
  • application.yml配置------------主要配置了单库水平分表操作

    https://blog.csdn.net/qq_36669347/article/details/107790213

    pom.xml 配置

    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.22</version>
    </dependency>

    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.0.0-RC1</version>
    </dependency>

    <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.4.1</version>
    </dependency>

    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>

    jdbc.properties 配置

    spring.shardingsphere.datasource.names=m1

    #配置第一个数据源具体内容,包含连接池,驱动,地址,用户名和密码
    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/course_db?serverTimezone=GMT%2B8
    spring.shardingsphere.datasource.m1.username=root
    spring.shardingsphere.datasource.m1.password=root

    spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}


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

    # 指定表分片策略 约定cid值偶数添加到course_1表,如果cid是奇数添加到course_2表
    spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
    spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid % 2 + 1}

    # 打开sql输出日志
    spring.shardingsphere.props.sql.show=true

    spring.main.allow-bean-definition-overriding=true
    ————————————————
    版权声明:本文为CSDN博主「陨落星辰wjj」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_36669347/article/details/107790213

  • 相关阅读:
    [转]给明年依然年轻的我们:欲望、外界、标签、天才、时间、人生目标、现实、后悔、和经历
    sql server 2005/2008 加密存储过程解密脚本/软件推荐
    将所有程序最小化到系统托盘RBTray strokeit TrayEverything
    [转]LeftLeaning RedBlack Tree
    emulator for the MIX computer (TAOCP)
    [转]Kindle电子书资源网站汇总
    鼻炎、鼻窦炎可尝试药膳
    C# 获取机器码(转)
    为输入提供动态提示框
    ProcessDialogKey 方法实现回车自动换行
  • 原文地址:https://www.cnblogs.com/zhoading/p/15320859.html
Copyright © 2011-2022 走看看