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