mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
update docs
This commit is contained in:
parent
a7b94bed46
commit
268ee05966
@ -82,13 +82,13 @@ export default defineConfig({
|
||||
{text: 'SQL 审计', link: '/zh/core/audit'},
|
||||
{text: 'SQL 打印', link: '/zh/core/sql-print'},
|
||||
{text: '多数据源', link: '/zh/core/multi-datasource'},
|
||||
{text: '动态表名', link: '/zh/core/dynamic-table'},
|
||||
{text: '事务管理', link: '/zh/core/tx'},
|
||||
{text: '数据权限', link: '/zh/core/data-permission'},
|
||||
{text: '字段权限', link: '/zh/core/columns-permission'},
|
||||
{text: '字段加密', link: '/zh/core/columns-encrypt'},
|
||||
{text: '字典回写', link: '/zh/core/columns-dict'},
|
||||
{text: '枚举属性', link: '/zh/core/enum-property'},
|
||||
{text: '动态表名', link: '/zh/core/dynamic-table'},
|
||||
{text: '多租户', link: '/zh/core/multi-tenancy'},
|
||||
]
|
||||
},
|
||||
|
||||
@ -66,10 +66,11 @@ List<Row> rows = DataSourceKey.use("ds2"
|
||||
|
||||
## 数据源切换(设置)
|
||||
|
||||
MyBatis-Flex 提供了 3 种方式来配置数据源:
|
||||
MyBatis-Flex 提供了 4 种方式来配置数据源:
|
||||
- 1、编码,使用`DataSourceKey.use` 方法。
|
||||
- 2、`@UseDataSource("dataSourceName")` 在 Mapper 方法上,添加注解,用于指定使用哪个数据源。
|
||||
- 3、`@Table(dataSource="dataSourceName")` 在 Entity 类上添加注解,该 Entity 的增删改查请求默认使用该数据源。
|
||||
- 2、`@UseDataSource("dataSourceName")` 在 Mapper 类上,添加注解,用于指定使用哪个数据源。
|
||||
- 3、`@UseDataSource("dataSourceName")` 在 Mapper 方法上,添加注解,用于指定使用哪个数据源。
|
||||
- 4、`@Table(dataSource="dataSourceName")` 在 Entity 类上添加注解,该 Entity 的增删改查请求默认使用该数据源。
|
||||
|
||||
|
||||
`DataSourceKey.use` 示例:
|
||||
@ -84,6 +85,15 @@ try{
|
||||
```
|
||||
|
||||
`@UseDataSource("dataSourceName")` 示例:
|
||||
|
||||
```java 1
|
||||
@UseDataSource("ds2")
|
||||
interface AccountMapper extends BaseMapper{
|
||||
List<Account> myMethod();
|
||||
}
|
||||
```
|
||||
|
||||
或者
|
||||
```java 3
|
||||
interface AccountMapper extends BaseMapper{
|
||||
|
||||
@ -92,6 +102,8 @@ interface AccountMapper extends BaseMapper{
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
`@Table(dataSource="dataSourceName")` 示例:
|
||||
```java 1
|
||||
@Table(value = "tb_account", dataSource = "ds2")
|
||||
@ -105,7 +117,7 @@ public class Account {
|
||||
```
|
||||
|
||||
::: tip 数据源配置的优先级
|
||||
`DataSourceKey.use()` > `@UseDataSource()` > `@Table(dataSource="...")`
|
||||
`DataSourceKey.use()` > `@UseDataSource()在方法上` > `@UseDataSource()在类上` >`@Table(dataSource="...")`
|
||||
:::
|
||||
|
||||
## 更多的 Spring Yaml 配置支持
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user