新增 sharding-jdbc 实例
This commit is contained in:
@ -1,13 +0,0 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ShardingJdbcExampleApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ShardingJdbcExampleApplication.class, args);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example.model.Demo;
|
||||
|
||||
@Mapper
|
||||
public interface DemoMapper extends BaseMapper<Demo> {
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example.model.UndoLog;
|
||||
|
||||
@Mapper
|
||||
public interface UndoLogMapper extends BaseMapper<UndoLog> {
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example.model;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Demo {
|
||||
|
||||
private Long id;
|
||||
private String col1;
|
||||
private String col2;
|
||||
|
||||
/** 参数自动注入 */
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
|
||||
private Date createTime;
|
||||
private String updateBy;
|
||||
private Date updateTime;
|
||||
private int delFlag;
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.shardingjdbc.example.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UndoLog {
|
||||
|
||||
private Long id;
|
||||
private Long branchId;
|
||||
private String xid;
|
||||
private String context;
|
||||
private String rollbackInfo;
|
||||
private Integer logStatus;
|
||||
private Date logCreated;
|
||||
private Date logModified;
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
spring:
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: ds0, ds0slave1, ds0slave2, ds1
|
||||
ds0:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://125.32.114.204:13306/ebtp-cloud?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: mall3-ebtp-dev
|
||||
password: mall3-ebtp-dev
|
||||
|
||||
# 从库
|
||||
ds0slave1:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://125.32.114.204:13306/ebtp-cloud?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: mall3-ebtp-dev
|
||||
password: mall3-ebtp-dev
|
||||
|
||||
ds0slave2:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://125.32.114.204:13306/ebtp-cloud?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: mall3-ebtp-dev
|
||||
password: mall3-ebtp-dev
|
||||
|
||||
ds1:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://125.32.114.204:13306/ebtp_mall_evaluation?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: mall3-ebtp-dev
|
||||
password: mall3-ebtp-dev
|
||||
|
||||
# 分库配置
|
||||
sharding:
|
||||
tables:
|
||||
demo:
|
||||
actual-data-nodes: ds0.demo
|
||||
undo_log:
|
||||
actual-data-nodes: ds1.undo_log
|
||||
|
||||
#读写分离
|
||||
master-slave-rules:
|
||||
ds0:
|
||||
master-data-source-name: ds0
|
||||
slave-data-source-names:
|
||||
- ds0slave1
|
||||
- ds0slave2
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: shardingJdbc
|
||||
application:
|
||||
name: mall-ebtp-cloud-demo
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
|
Reference in New Issue
Block a user