mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 集成 ShardingSphere-JDBC 最新版,分表存储小说内容(默认关闭)
默认关闭分库分表,通过配置属性 shardingsphere.enabled 来开启
This commit is contained in:
parent
bf60ba30c9
commit
5d0ac13ae6
8
pom.xml
8
pom.xml
@ -21,6 +21,7 @@
|
|||||||
<elasticsearch.version>8.2.0</elasticsearch.version>
|
<elasticsearch.version>8.2.0</elasticsearch.version>
|
||||||
<xxl-job.version>2.3.1</xxl-job.version>
|
<xxl-job.version>2.3.1</xxl-job.version>
|
||||||
<sentinel.version>1.8.4</sentinel.version>
|
<sentinel.version>1.8.4</sentinel.version>
|
||||||
|
<shardingsphere-jdbc.version>5.1.1</shardingsphere-jdbc.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -137,6 +138,13 @@
|
|||||||
<version>${sentinel.version}</version>
|
<version>${sentinel.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- ShardingSphere-JDBC -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
|
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||||
|
<version>${shardingsphere-jdbc.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
@ -20,6 +20,44 @@ spring:
|
|||||||
url: jdbc:mysql://localhost:3306/novel_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://localhost:3306/novel_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
username: root
|
username: root
|
||||||
password: test123456
|
password: test123456
|
||||||
|
# 分库分表配置
|
||||||
|
shardingsphere:
|
||||||
|
datasource:
|
||||||
|
names: ds_0
|
||||||
|
ds_0:
|
||||||
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
jdbcUrl: jdbc:mysql://localhost:3306/novel_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
|
username: root
|
||||||
|
password: test123456
|
||||||
|
rules:
|
||||||
|
sharding:
|
||||||
|
tables:
|
||||||
|
# book_content表
|
||||||
|
book_content:
|
||||||
|
# 数据节点
|
||||||
|
actual-data-nodes: ds_$->{0}.book_content$->{0..9}
|
||||||
|
# 分表策略
|
||||||
|
table-strategy:
|
||||||
|
standard:
|
||||||
|
# 分片列名称
|
||||||
|
sharding-column: chapter_id
|
||||||
|
# 分片算法名称
|
||||||
|
sharding-algorithm-name: bookContentSharding
|
||||||
|
sharding-algorithms:
|
||||||
|
bookContentSharding:
|
||||||
|
# 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
|
||||||
|
type: INLINE
|
||||||
|
props:
|
||||||
|
# 分片算法的行表达式
|
||||||
|
algorithm-expression: book_content$->{chapter_id % 10}
|
||||||
|
props:
|
||||||
|
# 是否在日志中打印 SQL
|
||||||
|
sql-show: true
|
||||||
|
# 是否开启分库分表
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
|
||||||
config:
|
config:
|
||||||
activate:
|
activate:
|
||||||
on-profile: dev
|
on-profile: dev
|
||||||
|
Loading…
x
Reference in New Issue
Block a user