联表查询处理类
- 使用
json的{}或[]方式进行查询 - 默认传参:
unionFormat
OneToOne
- 表示一对一的关系
- 通常通过
外键来实现这种关系 - 映射内容为对象
联表查询字段
| 序号 | 字段信息 | 描述 | 默认值 |
|---|---|---|---|
| 1 | field | 当前表字段 | - |
| 2 | table | 外键表名称 | |
| 3 | key | 外键表字段 | id |
| 4 | view | 映射字段(为空:默认当前表字段field,不能为id) | - |
| 5 | nullable | 是否可为空(为空返回{}、[]) | true |
| 6 | type | 返回数据对象类型(Object、Array) | Object |
完整案例
json
{
"field": "org-1",
"table": "org",
"key": "id",
"view": "org",
"nullable": false, // 不可以为空
"type":"Object"
}简化案例
json
{
"field": "org-1",
"table": "org"
}默认映射字段
- 联表查询前
json
{
"id": "user-1",
"oid": "org-1",
"rid": "role-1",
"name": "用户名"
}- 联表查询规则
json
[
{
"field": "org-1",
"table": "org",
"key": "id",
"nullable": false, // 不可以为空
"type":"Object"
},
{
"field": "role-1",
"table": "role",
"key": "id",
"nullable": false, // 不可以为空
"type":"Object"
}
]- 联表查询后
json
{
"id": "user-1",
"oid": {
"id": "org-1",
"name": "部门"
},
"rid": {
"id": "role-1",
"name": "角色"
},
"name": "用户名"
}指定映射字段
- 联表查询前
json
{
"id": "user-1",
"oid": "org-1",
"rid": "role-1",
"name": "用户名"
}- 联表查询规则
json
[
{
"field": "org-1",
"table": "org",
"key": "id",
"view": "org",
"nullable": false, // 不可以为空
"type":"Object"
},
{
"field": "role-1",
"table": "role",
"key": "id",
"view": "role",
"nullable": false, // 不可以为空
"type":"Object"
}
]- 联表查询后
json
{
"id": "user-1",
"oid": "org-1",
"rid": "role-1",
"name": "用户名",
"org": {
"id": "org-1",
"name": "部门"
},
"role": {
"id": "role-1",
"name": "角色"
}
}OneToMany
- 表示一对多的关系
- 通常通过
主键来实现这种关系 - 映射内容为数组
联表查询字段
| 序号 | 字段信息 | 描述 | 默认值 |
|---|---|---|---|
| 1 | field | 当前表字段 | id |
| 2 | table | 外键表名称 | |
| 3 | key | 外键表字段 | - |
| 4 | view | 映射字段(为空:默认当前表字段field,不能为id) | - |
| 5 | nullable | 是否可为空(为空返回{}、[]) | true |
| 6 | type | 返回数据对象类型(Object、Array) | Array |
完整案例
json
{
"field": "id",
"table": "user",
"key": "depId",
"view": "users",
"nullable": true, // 可以为空
"type":"Array"
}简化案例
json
{
"table": "user",
"key": "depId",
"view": "users"
}指定映射字段
- 联表查询前
json
{
"id": "dept-1",
"name": "部门"
}- 联表查询规则
json
{
"field": "id",
"table": "user",
"key": "depId",
"view": "users",
"nullable": true, // 可以为空
"type":"Array"
}- 联表查询后
json
{
"id": "dept-1",
"name": "部门",
"users": [
]
}ManyToMany
- 表示多对多的关系
- 通常通过
中间表来实现这种关系 - 映射内容为数组
联表查询字段
| 序号 | 字段信息 | 描述 | 默认值 |
|---|---|---|---|
| 1 | field | 当前表字段 | id |
| 2 | table | 外键表名称 | |
| 3 | key | 外键表字段 | id |
| 4 | view | 映射字段(不为空) | - |
| 5 | nullable | 是否可为空(为空返回{}、[]) | true |
| 6 | type | 返回数据对象类型(Object、Array) | Array |
| 7 | join | 中间表,及外键信息 |
中间表字段
| 序号 | 字段信息 | 描述 | 默认值 |
|---|---|---|---|
| 1 | field | 当前表字段 | |
| 2 | table | 外键表名称 | |
| 3 | key | 外键表字段 |
完整案例
json
{
"field": "id",
"table": "role",
"key": "id",
"view": "roles",
"nullable": true, // 可以为空
"type":"Array",
"join":{
"field": "userid",
"table": "userRole",
"key": "roleId"
}
}简化案例
json
{
"table": "role",
"view": "roles",
"join":{
"field": "userid",
"table": "userRole",
"key": "roleId"
}
}