项目地址:php
官方文档:html
修改config包下MybaitsPlusConfig.java,获取当前登陆用户的租户ID,这里默认写1
@Override public Expression getTenantId() { try { // 获取当前登陆用户租户ID String tenantId = "1"; if (!StrUtil.isEmpty(tenantId)) { return new LongValue(tenantId); } throw new Exception(RetBack.errorJson(4001, "该租户不存在")); } catch (Exception e) { e.printStackTrace(); } return new LongValue(-1L); }
本项目为两个数据源实现分库和分表,若是只分表不分库,只须要添加一个数据源便可java
@SpringBootApplication(exclude = {DruidDataSourceAutoConfigure.class, DataSourceAutoConfiguration.class})
若是不使用Sharding-JDBC,而须要多数据源,能够采用Mybaits-Plus多数据源方案,详见官方文档,后面我会把示例项目分享给你们,敬请期待。能够加我互相交流。git
<center style="font-size:18px">开源不易,且用且珍惜!</center>github
<center style="font-size:16px">赞助做者,互相交流</center>
算法
<div style="display:flex;justify-content:center;align-item:center">
<img src="https://user-gold-cdn.xitu.io/2020/5/29/1725e23e1228866e?w=1080&h=1080&f=png&s=342366" style="width:180px;height:180px;padding:20px"/>sql
<img src="https://user-gold-cdn.xitu.io/2020/5/29/1725e23e121cbaa2?w=300&h=299&f=gif&s=20783" style="width:180px;height:180px;padding:20px"/>
</div>数据库
转载请注明:个人技术分享 » Sharding-Jdbc集成mybatis-plus实现分库分表解决方案apache