MyBatis-Plus 自定义多数据源注解
MyBatis-Plus About 725 words说明
dynamic-datasource自带了@Master和@Slave注解。
自定义注解
application.yaml配置,datasource下申明需要自定义的注解对应的数据库名称。
spring:
datasource:
dynamic:
datasource:
clickhouse:
driver-class-name: com.clickhouse.jdbc.ClickHouseDriver
url: jdbc:clickhouse://localhost:8123/clickhousedb
username: clickhouseuser
password: clickhousepwd
如下定义了Clickhouse注解,@DS()中填写对应application.yaml配置中申明的数据库名称。
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@DS("clickhouse")
public @interface Clickhouse {
}
使用
@RestController
public class TestController {
@Clickhouse
@GetMapping("/users")
public List<User> users() {
return xxx;
}
}
Views: 973 · Posted: 2024-12-17
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...