springboot+dynamic多数据源配置
生活随笔
收集整理的這篇文章主要介紹了
springboot+dynamic多数据源配置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
springboot+dynamic多數(shù)據(jù)源配置
配置
使用
@Service
@DS("slave")
public class UserServiceImpl implements UserService {@Autowiredprivate JdbcTemplate jdbcTemplate;public List<Map<String, Object>> selectAll() {return jdbcTemplate.queryForList("select * from user");}@Override@DS("slave_1")public List<Map<String, Object>> selectByCondition() {return jdbcTemplate.queryForList("select * from user where age >10");}
}
來自為知筆記(Wiz)
配置
使用
springboot+dynamic多數(shù)據(jù)源配置
來源:https://mp.baomidou.com/guide/dynamic-datasource.html
dynamic-datasource-spring-boot-starter 是一個基于springboot的快速集成多數(shù)據(jù)源的啟動器。
配置
- pom
- 配置數(shù)據(jù)源。
使用
使用@DS切換數(shù)據(jù)源。
@DS可以注解在方法上和類上,同時存在方法注解優(yōu)先于類上注解。
| 沒有@DS | 默認(rèn)數(shù)據(jù)源 |
| @DS("dsName") | dsName可以為組名也可以為具體某個庫的名稱 |
來自為知筆記(Wiz)
轉(zhuǎn)載于:https://www.cnblogs.com/ziyue7575/p/e97bcad8ed323602251ca3bd2b1a4457.html
總結(jié)
以上是生活随笔為你收集整理的springboot+dynamic多数据源配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: plsqlnbsp;分页
- 下一篇: PhotoShop更改图片背景色