doc: update docs

This commit is contained in:
开源海哥 2023-09-18 09:27:41 +08:00
parent 0f4f31a30e
commit 23f4af9e57

View File

@ -352,10 +352,10 @@ public class Account implements Serializable {
}
```
Relation结果集只使用某个字段值-`since v1.6.6`
## 只查询一个字段值 <Badge type="tip" text="v1.6.6" />
`RelationOneToOne``RelationOneToMany``RelationManyToOne``RelationManyToMany`新增属性`valueField`
```java {7-11}
```java 7
/**
* 目标对象的关系实体类的属性绑定
* <p>
@ -366,20 +366,17 @@ Relation结果集只使用某个字段值-`since v1.6.6`
```
> 注解其他属性配置使用不变,当配置了`valueField`值时,只提取目标对象关系实体类的该属性
>
> 注意:因为不是对象接收,所以该配置需要强制配置注解`targetTable`属性(因为是某个字段接收,并不是某个实体对应的表,所以需要增加`targetTable`获取目标表信息)
>
> 示例场景有个业务有个操作日志操作日志中有个createBy(操作人字段),此时在日志详情或者说日志列表中需要显示操作人名称,且只需要这一个字段,此时使用实体接收会导致不必要的字段出现,接口文档也会变得混乱。该场景也可以使用`Field Query``Join Query`实现
>
假设一个账户
> **使用场景**:例如,操作日志中有个 `createBy` (操作人)字段,此时在日志信息中需要显示操作人名称,且只需要这一个字段,此时使用实体接收会导致不必要的字段出现,接口文档也会变得混乱。
假设一个账户实体类 `UserVO5.java`
- 每个账户有一个唯一对应的`id_number`列在表`tb_id_card`
- 每个账户拥有多个订单`tb_user_order`
- 一个账户可以有多个角色,一个角色也可以分配给多个账户,他们通过中间表`tb_user_role`进行关系映射
```java {7-11}
```java {12,21,29}
@Table("tb_user")
public class UserVO5 implements Serializable {
private static final long serialVersionUID = 474700189859144273L;
public class UserVO5 {
@Id
private Integer userId;
private String userName;
@ -394,13 +391,6 @@ public class UserVO5 implements Serializable {
//该处可以定义其他属性名,不一定要是目标对象的字段名
private String idNumberCustomFieldName;
@RelationOneToMany(
selfField = "userId",
targetTable = "tb_user_order",
targetField = "userId",
valueField = "orderId"
)
private List<Integer> orderIdList;
@RelationManyToMany(
selfField = "userId",
@ -419,16 +409,16 @@ public class UserVO5 implements Serializable {
进行查询
```java
List<UserVO5> userVO5List = userMapper.selectListWithRelationsByQueryAs(QueryWrapper.create(), UserVO5.class);
System.out.println(userVO5List);
System.out.println(JSON.toJSONString(userVO5List));
```
输出结果
```json
[{
```json {6,7,13,14,20,21}
[
{
userId = 1,
userName = '张三',
password = '12345678',
idNumberCustomFieldName = 'F281C807-C40B-472D-82F5-6130199C6328',
orderIdList = [1],
roleNameList = [普通用户]
},
{
@ -436,7 +426,6 @@ System.out.println(userVO5List);
userName = '李四',
password = '87654321',
idNumberCustomFieldName = '6176E9AD-36EF-4201-A5F7-CCE89B254952',
orderIdList = [3, 2],
roleNameList = [普通用户, 贵族用户]
},
{
@ -444,17 +433,9 @@ System.out.println(userVO5List);
userName = '王五',
password = '09897654',
idNumberCustomFieldName = 'A038E6EA-1FDE-4191-AA41-06F78E91F6C2',
orderIdList = [6, 5, 4],
roleNameList = [普通用户, 贵族用户, 超级贵族用户]
},
{
userId = 4,
userName = '苏六',
password = '45678345',
idNumberCustomFieldName = 'A33E8BAA-93F2-4E28-A161-15CF7D0AE6D0',
orderIdList = [],
roleNameList = [普通用户, 贵族用户, 超级贵族用户, 管理员用户]
}]
}
]
```
## 父子关系查询