shardingjdbc每月分表_shardingjdbc分库分表测试

本文档展示了如何在SpringBoot项目中集成Mybatis-Plus和Sharding-JDBC进行数据库分库分表配置。详细配置包括pom.xml的依赖引入,application.yml的数据库连接、分片策略以及Mybatis-Plus的相关设置。
摘要由CSDN通过智能技术生成

springboot + mybatis-plus + mysql + sharding-jdbc

部分配置:

pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.2.0.M3

com.shardingjdbc

shardingjdbc

0.0.1-SNAPSHOT

shardingjdbc

shardingjdbc project for Spring Boot

1.8

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-tomcat

org.springframework.boot

spring-boot-starter-undertow

commons-dbcp

commons-dbcp

1.4

com.baomidou

mybatis-plus

2.1.9

com.baomidou

mybatisplus-spring-boot-starter

1.0.5

mysql

mysql-connector-java

5.1.47

io.shardingsphere

sharding-jdbc-spring-boot-starter

3.0.0.M4

org.springframework.boot

spring-boot-maven-plugin

application.yml

server:

# 端口

port: 1818

undertow:

# 编码

uri-encoding: UTF-8

spring:

main:

allow-bean-definition-overriding: true

resources:

# 静态资源文件夹

static-locations: classpath:/

# 序列化

jackson:

date-format: yyyy-MM-dd HH:mm:ss

time-zone: GMT+8

serialization:

#忽略无法转换的对象

fail_on_empty_beans: false

deserialization:

#允许对象忽略json中不存在的属性

fail_on_unknown_properties: false

#设置空如何序列化

defaultPropertyInclusion: ALWAYS

parser:

#允许出现特殊字符和转义符

allow_unquoted_control_chars: true

#允许出现单引号

allow_single_quotes: true

# 分库

sharding:

jdbc:

datasource:

names: shard1,shard2

shard1:

type: org.apache.commons.dbcp.BasicDataSource

driver-class-name: com.mysql.jdbc.Driver

url: jdbc:mysql://localhost:3306/shard1

username: root

password: root

shard2:

type: org.apache.commons.dbcp.BasicDataSource

driver-class-name: com.mysql.jdbc.Driver

url: jdbc:mysql://localhost:3306/shard2

username: root

password: root

config:

sharding:

# 默认数据源(未设置分表策略的表将默认用此数据源)

default-datasource-name: shard1

# 默认分库策略

default-database-strategy:

standard:

sharding-column: id

precise-algorithm-class-name: com.shardingjdbc.config.sharding.DataBasePreciseRule

# 分表策略

tables:

# 分库分表

table_one:

actual-data-nodes: shard$->{1..2}.table_one_$->{1..2}

table-strategy:

standard:

sharding-column: id

precise-algorithm-class-name: com.shardingjdbc.config.sharding.DataTablePreciseRule

# mybatis-plus 的分页插件

pagehelper:

helper-dialect: mysql

params: count=countSql

reasonable: false

support-methods-arguments: true

# mybatis-plus

mybatis-plus:

mapper-locations: /mapper/**/**.xml

typeAliasesPackage: com.shardingjdbc.domain

global-config:

id-type: 3

field-strategy: 2

db-column-underline: true

refresh-mapper: true

configuration:

map-underscore-to-camel-case: true

cache-enabled: false

call-setters-on-nulls: true

其他代码详见git仓库:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值