Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
d0f9d1b9
microservices-platform
项目概览
zhangjian1949
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d0f9d1b9
编写于
4月 08, 2019
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增sharding-jdbc-demo分库分表演示工程(sharding-sphere3.1.0)
上级
43730902
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
556 addition
and
2 deletion
+556
-2
README.md
README.md
+3
-1
pom.xml
pom.xml
+6
-1
zlt-business/user-center/src/main/java/com/central/user/config/MybatisPlusConfig.java
.../main/java/com/central/user/config/MybatisPlusConfig.java
+3
-0
zlt-demo/pom.xml
zlt-demo/pom.xml
+2
-0
zlt-demo/sharding-jdbc-demo/README.md
zlt-demo/sharding-jdbc-demo/README.md
+51
-0
zlt-demo/sharding-jdbc-demo/pom.xml
zlt-demo/sharding-jdbc-demo/pom.xml
+44
-0
zlt-demo/sharding-jdbc-demo/sharding-jdbc-demo.sql
zlt-demo/sharding-jdbc-demo/sharding-jdbc-demo.sql
+88
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/ShardingApplication.java
...-demo/src/main/java/com/sharding/ShardingApplication.java
+16
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/TestApplication.java
...jdbc-demo/src/main/java/com/sharding/TestApplication.java
+24
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/config/MybatisPlusConfig.java
...main/java/com/sharding/demo/config/MybatisPlusConfig.java
+23
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/controller/UserController.java
...ain/java/com/sharding/demo/controller/UserController.java
+68
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/mapper/UserMapper.java
...mo/src/main/java/com/sharding/demo/mapper/UserMapper.java
+11
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/model/User.java
...jdbc-demo/src/main/java/com/sharding/demo/model/User.java
+18
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/service/IUserService.java
...src/main/java/com/sharding/demo/service/IUserService.java
+11
-0
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/service/impl/UserServiceImpl.java
.../java/com/sharding/demo/service/impl/UserServiceImpl.java
+18
-0
zlt-demo/sharding-jdbc-demo/src/main/resources/application-master-slave.yml
...jdbc-demo/src/main/resources/application-master-slave.yml
+31
-0
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-databases.yml
...emo/src/main/resources/application-sharding-databases.yml
+29
-0
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-databases2.yml
...mo/src/main/resources/application-sharding-databases2.yml
+29
-0
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-databases3.yml
...mo/src/main/resources/application-sharding-databases3.yml
+36
-0
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-tables.yml
...c-demo/src/main/resources/application-sharding-tables.yml
+23
-0
zlt-demo/sharding-jdbc-demo/src/main/resources/application.yml
...emo/sharding-jdbc-demo/src/main/resources/application.yml
+22
-0
未找到文件。
README.md
浏览文件 @
d0f9d1b9
...
...
@@ -37,7 +37,7 @@
## 2. 项目总体架构图
![](
http
s://gitee.com/zlt2000/images/raw/master/springcloud微服务架构图.jpg
)
![](
http
://processon.com/chart_image/5c7f2ad6e4b02b2ce48d6835.png?_=1554621571250
)
...
...
@@ -73,6 +73,7 @@
*
应用吞吐量监控(qps、rt)
*
服务降级、熔断监控
*
服务限流监控
*
分库分表、读写分离
*
**业务基础功能支撑**
*
高性能方法级幂等性支持
*
RBAC权限管理,实现细粒度控制(方法、url级别)
...
...
@@ -122,6 +123,7 @@ central-platform -- 父项目,公共依赖
│
│
├─
txlcn
-
tm
-- tx-lcn事务管理器[7970]
│
├─
zlt
-
demo
-- demo一级工程
│
│
├─
txlcn
-
demo
-- txlcn的demo
│
│
├─
sharding
-
jdbc
-
demo
-- sharding-jdbc的demo
```
...
...
pom.xml
浏览文件 @
d0f9d1b9
...
...
@@ -22,7 +22,7 @@
<jjwt.version>
0.9.1
</jjwt.version>
<druid-starter>
1.1.10
</druid-starter>
<jasypt.version>
1.14
</jasypt.version>
<sharding-
jdbc>
2.0.3
</sharding-jdbc
>
<sharding-
sphere.version>
3.1.0
</sharding-sphere.version
>
<security-oauth2.version>
2.3.5.RELEASE
</security-oauth2.version>
<security-jwt.version>
1.0.9.RELEASE
</security-jwt.version>
<redisson.version>
3.9.1
</redisson.version>
...
...
@@ -280,6 +280,11 @@
<artifactId>
txlcn-txmsg-netty
</artifactId>
<version>
${txlcn.version}
</version>
</dependency>
<dependency>
<groupId>
io.shardingsphere
</groupId>
<artifactId>
sharding-jdbc-spring-boot-starter
</artifactId>
<version>
${sharding-sphere.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
zlt-business/user-center/src/main/java/com/central/user/config/MybatisPlusConfig.java
浏览文件 @
d0f9d1b9
...
...
@@ -14,6 +14,9 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan
({
"com.central.user.mapper*"
})
public
class
MybatisPlusConfig
extends
DefaultMybatisPlusConfig
{
/**
* 逻辑删除注入器
*/
@Bean
public
ISqlInjector
sqlInjector
(){
return
new
LogicSqlInjector
();
...
...
zlt-demo/pom.xml
浏览文件 @
d0f9d1b9
...
...
@@ -12,5 +12,7 @@
<modules>
<!-- txlcn分布式事务demo -->
<module>
txlcn-demo
</module>
<!-- sharding-jdbc分库分表demo -->
<module>
sharding-jdbc-demo
</module>
</modules>
</project>
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/README.md
0 → 100644
浏览文件 @
d0f9d1b9
[TOC]
## 一、说明
本demo的配置是修改自官方example,用于在本项目的依赖下集成sharding-jdbc来实现分库分表、读写分离等场景的演示
sharding-jdbc详细的配置项说明:https://www.kancloud.cn/zlt2000/microservices-platform/1015741
分库分表思路:https://www.kancloud.cn/zlt2000/microservices-platform/1015741
## 二、运行步骤
### 1. 修改application.yml配置
*
修改
`spring.profiles.active`
的值为需要运行的场景
1.
`master-slave`
:一主多从模式下的读写分离
2.
`sharding-databases`
:使用取模的方式来实现库分片
3.
`sharding-databases2`
:使用固定值的方式来实现库分片
4.
`sharding-databases3`
:工程里既有分片的表,也有不分片的表(使用默认的库)
5.
`sharding-tables`
:使用取模的方式来实现表分片
*
修改数据库的配置
### 2. 初始化数据
执行
`zlt-demo\sharding-jdbc-demo\sharding-jdbc-demo.sql`
脚本
### 3. 启动工程
运行
`ShardingApplication`
## 三、测试接口
### 1. 初始化数据
生成10条用户数据
http://localhost:11001/init
### 2. 查询所有用户数据
http://localhost:11001/
### 3. 查询某个用户数据
http://localhost:11001/{id}
### 4. 清除所有数据
http://localhost:11001/clean
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/pom.xml
0 → 100644
浏览文件 @
d0f9d1b9
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-demo
</artifactId>
<version>
1.4.0
</version>
</parent>
<artifactId>
sharding-jdbc-demo
</artifactId>
<description>
sharding-jdbc分库分表demo
</description>
<dependencies>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-common-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
com.zlt
</groupId>
<artifactId>
zlt-db-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
io.shardingsphere
</groupId>
<artifactId>
sharding-jdbc-spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/sharding-jdbc-demo.sql
0 → 100644
浏览文件 @
d0f9d1b9
-----------------------------------------sharding-databases
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_0
;
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_1
;
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_0
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_1
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
-----------------------------------------sharding-databases2
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_alibaba
;
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_baidu
;
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_alibaba
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_baidu
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
-----------------------------------------master-slave
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_master
;
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_slave_0
;
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds_slave_1
;
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_master
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_slave_0
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
IF
NOT
EXISTS
demo_ds_slave_1
.
user
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
-----------------------------------------sharding-tables
CREATE
SCHEMA
IF
NOT
EXISTS
demo_ds
;
CREATE
TABLE
IF
NOT
EXISTS
demo_ds
.
user_0
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
IF
NOT
EXISTS
demo_ds
.
user_1
(
id
BIGINT
NOT
NULL
AUTO_INCREMENT
,
company_id
varchar
(
32
)
NOT
NULL
,
name
varchar
(
50
)
NULL
,
create_time
datetime
(
0
)
NULL
,
update_time
datetime
(
0
)
NULL
,
PRIMARY
KEY
(
id
)
);
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/ShardingApplication.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* sharding-jdbc demo
*
* @author zlt
*/
@SpringBootApplication
public
class
ShardingApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ShardingApplication
.
class
,
args
);
}
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/TestApplication.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding
;
import
com.central.common.utils.IdGenerator
;
/**
* sharding-jdbc demo
*
* @author zlt
*/
public
class
TestApplication
{
public
static
void
main
(
String
[]
args
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
long
userId
=
IdGenerator
.
getId
();
System
.
out
.
println
(
userId
);
userId
=
userId
&
15
;
System
.
out
.
println
(
userId
);
}
/*
long orderId = IdGenerator.getId();
System.out.println(orderId);
orderId = (orderId << 4) | userId;
System.out.println(orderId);*/
}
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/config/MybatisPlusConfig.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding.demo.config
;
import
com.baomidou.mybatisplus.core.injector.ISqlInjector
;
import
com.baomidou.mybatisplus.extension.injector.LogicSqlInjector
;
import
com.central.db.config.DefaultMybatisPlusConfig
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author zlt
*/
@Configuration
@MapperScan
({
"com.sharding.demo.mapper*"
})
public
class
MybatisPlusConfig
extends
DefaultMybatisPlusConfig
{
/**
* 逻辑删除注入器
*/
@Bean
public
ISqlInjector
sqlInjector
(){
return
new
LogicSqlInjector
();
}
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/controller/UserController.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding.demo.controller
;
import
com.sharding.demo.model.User
;
import
com.sharding.demo.service.IUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* @author zlt
*/
@RestController
public
class
UserController
{
private
final
IUserService
userService
;
@Autowired
public
UserController
(
IUserService
userService
)
{
this
.
userService
=
userService
;
}
/**
* 初始化数据
*/
@GetMapping
(
"/init"
)
public
String
initDate
()
{
String
companyId
;
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
User
u
=
new
User
();
if
(
i
%
2
==
0
)
{
companyId
=
"alibaba"
;
}
else
{
companyId
=
"baidu"
;
}
u
.
setCompanyId
(
companyId
);
u
.
setName
(
String
.
valueOf
(
i
));
userService
.
save
(
u
);
}
return
"success"
;
}
/**
* 查询列表
*/
@GetMapping
(
"/"
)
public
List
<
User
>
list
()
{
return
userService
.
list
();
}
/**
* 查询单条记录
*/
@GetMapping
(
"/{id}"
)
public
User
get
(
@PathVariable
Long
id
)
{
return
userService
.
getById
(
id
);
}
/**
* 清除数据
*/
@GetMapping
(
"/clean"
)
public
String
clean
()
{
userService
.
remove
(
null
);
return
"success"
;
}
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/mapper/UserMapper.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding.demo.mapper
;
import
com.central.db.mapper.SuperMapper
;
import
com.sharding.demo.model.User
;
/**
* @author zlt
*/
public
interface
UserMapper
extends
SuperMapper
<
User
>
{
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/model/User.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding.demo.model
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.central.common.model.SuperEntity
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
/**
* @author zlt
*/
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
@TableName
(
"user"
)
public
class
User
extends
SuperEntity
{
private
static
final
long
serialVersionUID
=
8898492657846787286L
;
private
String
companyId
;
private
String
name
;
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/service/IUserService.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding.demo.service
;
import
com.central.common.service.ISuperService
;
import
com.sharding.demo.model.User
;
/**
* @author zlt
*/
public
interface
IUserService
extends
ISuperService
<
User
>
{
}
zlt-demo/sharding-jdbc-demo/src/main/java/com/sharding/demo/service/impl/UserServiceImpl.java
0 → 100644
浏览文件 @
d0f9d1b9
package
com.sharding.demo.service.impl
;
import
com.central.common.service.impl.SuperServiceImpl
;
import
com.sharding.demo.mapper.UserMapper
;
import
com.sharding.demo.model.User
;
import
com.sharding.demo.service.IUserService
;
import
org.springframework.stereotype.Service
;
import
lombok.extern.slf4j.Slf4j
;
/**
* @author zlt
*/
@Slf4j
@Service
public
class
UserServiceImpl
extends
SuperServiceImpl
<
UserMapper
,
User
>
implements
IUserService
{
}
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/resources/application-master-slave.yml
0 → 100644
浏览文件 @
d0f9d1b9
sharding
:
jdbc
:
datasource
:
names
:
ds-master,ds-slave-0,ds-slave-1
ds-master
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_master?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
ds-slave-0
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_slave_0?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
ds-slave-1
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_slave_1?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
config
:
masterslave
:
load-balance-algorithm-type
:
round_robin
name
:
ds_ms
master-data-source-name
:
ds-master
slave-data-source-names
:
ds-slave-0,ds-slave-1
props
:
sql
:
show
:
true
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-databases.yml
0 → 100644
浏览文件 @
d0f9d1b9
sharding
:
jdbc
:
datasource
:
names
:
ds-0,ds-1
ds-0
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_0?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
ds-1
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_1?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
config
:
sharding
:
default-database-strategy
:
inline
:
sharding-column
:
id
algorithm-expression
:
ds-$->{id % 2}
tables
:
user
:
actual-data-nodes
:
ds-$->{0..1}.user
#key-generator-column-name: id
props
:
sql
:
show
:
true
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-databases2.yml
0 → 100644
浏览文件 @
d0f9d1b9
sharding
:
jdbc
:
datasource
:
names
:
ds-alibaba,ds-baidu
ds-alibaba
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_alibaba?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
ds-baidu
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_baidu?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
config
:
sharding
:
default-database-strategy
:
inline
:
sharding-column
:
company_id
algorithm-expression
:
ds-$->{company_id}
tables
:
user
:
actual-data-nodes
:
ds-$->{['alibaba','baidu']}.user
key-generator-column-name
:
id
props
:
sql
:
show
:
true
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-databases3.yml
0 → 100644
浏览文件 @
d0f9d1b9
sharding
:
jdbc
:
datasource
:
names
:
ds,ds-0,ds-1
ds
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
ds-0
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_0?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
ds-1
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds_1?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
config
:
sharding
:
default-data-source-name
:
ds
default-database-strategy
:
inline
:
sharding-column
:
id
algorithm-expression
:
ds-$->{id % 2}
tables
:
user
:
actual-data-nodes
:
ds-$->{0..1}.user
key-generator-column-name
:
id
props
:
sql
:
show
:
true
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/resources/application-sharding-tables.yml
0 → 100644
浏览文件 @
d0f9d1b9
sharding
:
jdbc
:
datasource
:
names
:
ds
ds
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
url
:
jdbc:mysql://${zlt.datasource.ip}:3306/demo_ds?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull
username
:
${zlt.datasource.username}
password
:
${zlt.datasource.password}
config
:
sharding
:
tables
:
user
:
actual-data-nodes
:
ds.user_$->{0..1}
table-strategy
:
inline
:
sharding-column
:
id
algorithm-expression
:
user_$->{id % 2}
key-generator-column-name
:
id
props
:
sql
:
show
:
true
\ No newline at end of file
zlt-demo/sharding-jdbc-demo/src/main/resources/application.yml
0 → 100644
浏览文件 @
d0f9d1b9
server
:
port
:
11001
spring
:
profiles
:
active
:
sharding-databases
application
:
name
:
sharding-jdbc-demo
zlt
:
datasource
:
ip
:
192.168.28.131
username
:
root
password
:
1q2w3e4r
mybatis-plus
:
mapper-locations
:
classpath:/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage
:
com.sharding.demo.model
global-config
:
db-config
:
id-type
:
ID_WORKER
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录