# mybatisplus-multi-datasource **Repository Path**: neo0627/mybatisplus-multi-datasource ## Basic Information - **Project Name**: mybatisplus-multi-datasource - **Description**: mybatisplus,多数据源 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 2 - **Created**: 2021-01-08 - **Last Updated**: 2022-10-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mybatisplus-multi-datasource #### 介绍 mybatisplus,多数据源 参考:https://dynamic-datasource.com/guide/ #### 说明 1. idea引入项目 ![输入图片说明](https://images.gitee.com/uploads/images/2021/0108/093108_7851caad_2229610.png "屏幕截图.png") 2. 初始化数据库 ![输入图片说明](https://images.gitee.com/uploads/images/2021/0108/093247_716ea168_2229610.png "屏幕截图.png") 3. run ``` MultiDataSourceApplication ``` 4. 浏览器访问http://localhost:9666/slave/list ![输入图片说明](https://images.gitee.com/uploads/images/2021/0108/093334_8733315a_2229610.png "屏幕截图.png") SlaveService采用注解@DS("slave"),调用MasterService.list(),一个方法使用两个数据库 ``` @Service @DS("slave") public class SlaveService { @Autowired SlaveMapper masterMapper; @Autowired MasterService masterService; public List list(){ Wrapper wrapper = new QueryWrapper(); List list = masterMapper.selectList(wrapper); List masterList = masterService.list(); System.out.println(masterList); return list; } } ``` MasterService ``` @Service public class MasterService{ @Autowired MasterMapper masterMapper; @DS("master") public List list(){ Wrapper wrapper = new QueryWrapper(); List list = masterMapper.selectList(wrapper); return list; } } ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)