doc: 添加 VO 类重名映射说明。

This commit is contained in:
Suomm 2024-04-12 10:26:04 +08:00
parent 00b28a052d
commit 3e23a68b6c

View File

@ -272,6 +272,7 @@ List<AccountVO> bookVos = QueryChain.of(accountMapper)
在很多类型嵌套的场景下,可能会出现字段名定义重复的情况,例如:
```java
@TableRef(Account.class)
public class AccountVO {
private Long id;
@ -311,7 +312,9 @@ List<AccountVO> bookVos = QueryChain.of(accountMapper)
其执行的 SQL 如下:
```sql
select tb_account.id, tb_account.name, tb_account.age,
select tb_account.id as tb_account$id,
tb_account.name as tb_account$name,
tb_account.age,
tb_book.id as tb_book$id, -- Flex 发现有重名时,会自动添加上 as 别名
tb_book.name as tb_book$name -- Flex 发现有重名时,会自动添加上 as 别名
from tb_account
@ -321,8 +324,9 @@ where tb_account.id >= 100
此时,查询的数据可以正常映射到 `AccountVO` 类。
> 注意,在 QueryWrapper 的 `select(...)`MyBatis-Flex 在 **多表查询** 的情况下且有相同的字段名时MyBatis-Flex
> 内部会主动帮助用户添加上 as 别名,默认为:`表名$字段名`
::: tip 注意事项
- 在查询 VO 类当中有重名字段时,需要给 VO 类标记 `@TableRef` 注解,指定其对应的实体类,以正确添加别名。
- 在 QueryWrapper 的 `select(...)`MyBatis-Flex 在 **多表查询** 的情况下且有相同的字段名时MyBatis-Flex 内部会主动帮助用户添加上 as 别名,默认为:`表名$字段名`
**错误的情况:**