效果图
默认查询主库

切换到从库

不分页
 
分页
 
默认分页

源代码
git clone https://gitee.com/a2953557740/datasource.git
使用教程
执行sql
CREATE DATABASE `master` ;
USE `master`;
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`test_id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`test_name` varchar(20) NOT NULL COMMENT '名称',
PRIMARY KEY (`test_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb3;
insert into `test`(`test_id`,`test_name`) values (1,'master1'),(2,'master2'),(3,'master3'),(4,'master4'),(5,'master5'),(6,'master6'),(7,'主库1'),(8,'主库2'),(9,'主库3'),(10,'主库4'),(11,'主库5'),(12,'主库6');
CREATE DATABASE `slave` ;
USE `slave`;
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`test_id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
`test_name` varchar(20) NOT NULL COMMENT '名称',
PRIMARY KEY (`test_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb3;
insert into `test`(`test_id`,`test_name`) values (1,'slave1'),(2,'slave2'),(3,'slave3'),(4,'slave4'),(5,'slave5'),(6,'slave6'),(7,'从库1'),(8,'从库2'),(9,'从库3'),(10,'从库4'),(11,'从库5'),(12,'从库6');
下载源码,导入到idea,run WebApplication
在浏览器页面进行测试
|