3、使用 @DS 切换数据源 。
文章插图
import com.baomidou.dynamic.datasource.annotation.DS;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import com.test.moredatasourse.Service.TtService;import com.test.moredatasourse.bean.Tt;import com.test.moredatasourse.mapper.SsMapper;import com.test.moredatasourse.mapper.TtMapper;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import JAVA.util.List;@Service@DS("slave_1")public class TtServiceImpl extends ServiceImpl<TtMapper, Tt> implements TtService {@Autowiredprivate TtMapper ttMapper;@Overridepublic List<Tt> info() {List<Tt> tts = ttMapper.selectList(null);return tts;}}
推荐阅读
- 10分钟快速搭建小程序管理后台,云开发CMS搭建可视化后台
- MySQL如何删除重复数据
- reGeorg搭建HTTP隧道和流量分析
- MySQL运行机制
- MySQL5.7数据库主从架构部署,你再也不用去问度娘了
- MySQL高可用架构的演进
- CENTOS Mysql5.7数据库自动安装脚本
- 怎样用3分钟搭建 Python 人脸识别系统
- 做好mysql运维,必须熟练掌握备份和恢复,实战一次不行多来几次
- MySQL还能实现分布式锁?