# SpringBoot-ShardingSphere **Repository Path**: linyunnuo/spring-boot-sharding-sphere ## Basic Information - **Project Name**: SpringBoot-ShardingSphere - **Description**: SpringBoot集成ShardingSphere进行分库分表操作Demo示例,其中集成了Springboot+Mybatis-Plus+ShardingSphere+Mysql进行分库分表的代码示例,其中包含了测试类,用于随机生成分库分表的用户模拟数据测试接口、根据id查询分库分表的测试数据所在库表的位置、分页查询分库分表数据、默认库没有进行分库分表数据的新增和分页查询接口。 - **Primary Language**: Java - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-04-12 - **Last Updated**: 2023-01-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Sharding-sphere-demo项目Demo ## 项目Demo简介 >SpringBoot集成ShardingSphere进行分库分表操作Demo示例, > 其中集成了Springboot+Mybatis-Plus+ShardingSphere+LomBok+Mysql进行分库分表的代码示例, > 其中包含了测试类,用于随机生成分库分表的用户模拟数据测试接口、根据id查询分库分表的测试数据所在库表的位置、分页查询分库分表数据 > 、默认库没有进行分库分表数据的新增和分页查询接口。 ## 使用教程 1. 新增库:`sharding-user-0` 到 `sharding-user-7` 依次递增,然后在sql文件夹中在各个库中执行`user.sql` 进行新增`user_0` 到 `user_9` 表数据 2. 新增默认主库:sharding-master ,然后执行`masterTest.sql` 进行新增默认主库表:`master_test`表 如下图所示: ![输入图片说明](images/imagesimage.png) 3. 在`src/main/resources/application.yml` 中更改MySQL的用户和密码 ```yaml username: ${MYSQL_USER:root} password: ${MYSQL_PASSWD:root} ``` 4. 启动`com.yunnuo.com.App` 对项目进行启动后,可以在`httpReq`文件夹中 执行`generated-requests.http`的请求,查询或者新增数据 ```http request ### 新增分库分表 user 信息 POST http://localhost:8890/api/user/add Content-Type: application/json { "name": "测试用户666", "password": "root", "sex": 1 } ### 根据用户id 查询当前用户所在库表位置 GET http://localhost:8890/api/user/getByUserId/1529823481171366016 ### 获取分库分表user分页数据 POST http://localhost:8890/api/user/page Content-Type: application/json { "pageIndex": 0, "pageSize": 10 } ### 获取默认主库 master_test分页数据 POST http://localhost:8890/master/test/page Content-Type: application/json { "pageIndex": 0, "pageSize": 10 } ### 新增默认库 master_test 数据 POST http://localhost:8890/master/test/save Content-Type: application/json { "id": 0, "title": "测试数据", "content": "测试数据测试数据测试数据测试数据" } ``` ## 新增分库分表用户测试数据 > 启动 `src/test/java/com/yunnuo/com/SysUserServiceTest.java` 的`updateBatch`方法即可进行数据进行新增