mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-02 02:25:27 +08:00
最新版分库分表集成示例 nacos配置文件
This commit is contained in:
@ -0,0 +1,59 @@
|
||||
spring:
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: ds0,ds1
|
||||
ds0:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://jeecg-boot-mysql:3306/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
username: root
|
||||
password: root
|
||||
ds1:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://jeecg-boot-mysql:3306/jeecg-boot2?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
username: root
|
||||
password: root
|
||||
props:
|
||||
sql-show: true
|
||||
rules:
|
||||
replica-query:
|
||||
load-balancers:
|
||||
round-robin:
|
||||
type: ROUND_ROBIN
|
||||
props:
|
||||
default: 0
|
||||
data-sources:
|
||||
prds:
|
||||
primary-data-source-name: ds0
|
||||
replica-data-source-names: ds1
|
||||
load-balancer-name: round_robin
|
||||
sharding:
|
||||
binding-tables:
|
||||
- sys_log
|
||||
key-generators:
|
||||
snowflake:
|
||||
type: SNOWFLAKE
|
||||
props:
|
||||
worker-id: 123
|
||||
sharding-algorithms:
|
||||
table-classbased:
|
||||
props:
|
||||
strategy: standard
|
||||
algorithmClassName: org.jeecg.modules.test.sharding.algorithm.StandardModTableShardAlgorithm
|
||||
type: CLASS_BASED
|
||||
database-inline:
|
||||
type: INLINE
|
||||
props:
|
||||
algorithm-expression: ds$->{operate_type % 2}
|
||||
tables:
|
||||
sys_log:
|
||||
actual-data-nodes: ds$->{0..1}.sys_log$->{0..1}
|
||||
database-strategy:
|
||||
standard:
|
||||
sharding-column: operate_type
|
||||
sharding-algorithm-name: database-inline
|
||||
table-strategy:
|
||||
standard:
|
||||
sharding-algorithm-name: table-classbased
|
||||
sharding-column: log_type
|
||||
@ -0,0 +1,33 @@
|
||||
spring:
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: ds0
|
||||
ds0:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://jeecg-boot-mysql:3306/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
props:
|
||||
sql-show: true
|
||||
rules:
|
||||
sharding:
|
||||
binding-tables: sys_log
|
||||
key-generators:
|
||||
snowflake:
|
||||
type: SNOWFLAKE
|
||||
props:
|
||||
worker-id: 123
|
||||
sharding-algorithms:
|
||||
table-classbased:
|
||||
props:
|
||||
strategy: standard
|
||||
algorithmClassName: org.jeecg.modules.test.sharding.algorithm.StandardModTableShardAlgorithm
|
||||
type: CLASS_BASED
|
||||
tables:
|
||||
sys_log:
|
||||
actual-data-nodes: ds0.sys_log$->{0..1}
|
||||
table-strategy:
|
||||
standard:
|
||||
sharding-algorithm-name: table-classbased
|
||||
sharding-column: log_type
|
||||
@ -35,7 +35,8 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
@PostMapping(value = "/test1")
|
||||
@ApiOperation(value = "单库分表插入", notes = "单库分表")
|
||||
public Result<?> add() {
|
||||
int size=10;
|
||||
log.info("---------------------------------单库分表插入--------------------------------");
|
||||
int size = 10;
|
||||
for (int i = 0; i < size; i++) {
|
||||
ShardingSysLog shardingSysLog = new ShardingSysLog();
|
||||
shardingSysLog.setLogContent("jeecg");
|
||||
@ -43,7 +44,7 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
shardingSysLog.setOperateType(i);
|
||||
shardingSysLogService.save(shardingSysLog);
|
||||
}
|
||||
return Result.OK();
|
||||
return Result.OK("单库分表插入10条数据完成!");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,30 +58,30 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
}
|
||||
|
||||
/**
|
||||
* 双库分表 - 插入
|
||||
* 分库分表 - 插入
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/test2")
|
||||
@ApiOperation(value = "双库分表插入", notes = "双库分表")
|
||||
@ApiOperation(value = "分库分表插入", notes = "分库分表")
|
||||
public Result<?> test2() {
|
||||
int start=20;
|
||||
int size=30;
|
||||
int size=50;
|
||||
for (int i = start; i <= size; i++) {
|
||||
ShardingSysLog shardingSysLog = new ShardingSysLog();
|
||||
shardingSysLog.setLogContent("双库分表测试");
|
||||
shardingSysLog.setLogType(i);
|
||||
shardingSysLog.setLogContent("分库分表测试");
|
||||
shardingSysLog.setLogType(0);
|
||||
shardingSysLog.setOperateType(i);
|
||||
shardingSysLogService.save(shardingSysLog);
|
||||
}
|
||||
return Result.OK();
|
||||
return Result.OK("分库分表插入10条数据完成!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 双库分表 - 查询
|
||||
* 分库分表 - 查询
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/list2")
|
||||
@ApiOperation(value = "双库分表查询", notes = "双库分表")
|
||||
@ApiOperation(value = "分库分表查询", notes = "分库分表")
|
||||
public Result<?> list2() {
|
||||
return Result.OK(shardingSysLogService.list());
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
server:
|
||||
#微服务端口
|
||||
port: 7001
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: jeecg-system
|
||||
|
||||
Reference in New Issue
Block a user