spring-boot-note10---jdbc-sharding使用

本文介绍了如何在Spring Boot应用中整合jdbc-sharding进行数据库分库分表的操作,包括品牌brand在两个库dbs_0和dbs_1中的分库,以及产品product在dbs_0的product_0和product_1中的垂直分库水平分表。通过设置DDL语句、pom.xml配置、app.properties文件配置,实现了增删改查的正常功能,并进行了测试验证。
摘要由CSDN通过智能技术生成

jdbc-sharding整合spring-boot的使用。

demo简介:有一个brand表分别在dbs_0库和dbs_1库。有一个product表分别在dbs_0有product_0和product_1,即垂直分库水平分表,然后使用spring-boot整合jdbc-sharding的方式,完成增删改查操作。

一、ddl语句 数据库分别为:dbs_0  、dbs_1

DROP TABLE IF EXISTS `brand`;
CREATE TABLE `brand` (
  `id` bigint(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of brand
-- ----------------------------

-- ----------------------------
-- Table structure for product
-- ----------------------------
DROP TABLE IF EXISTS `product`;
CREATE TABLE `product` (
  `id` bigint(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `brand_id` bigint(11) DEFAULT NULL,
  `price` double(10,2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of product
-- ----------------------------

-- ----------------------------
-- Table structure for product_0
-- ----------------------------
DROP TABLE IF EXISTS `product_0`;
CREATE TABLE `product_0` (
  `id` bigint(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `price` double(10,2) DEFAULT NULL,
  `brand_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of product_0
-- ----------------------------

-- ----------------------------
-- Table structure for product_1
-- ----------------------------
DROP TABLE IF EXISTS `product_1`;
CREATE TABLE `product_1` (
  `id` bigint(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `price` double(10,2) DEFAULT NULL,
  `brand_id` bigint(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

二、pom.xml文件

 <dependencies>
 		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <grou
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值