Skip to content

联表查询处理类

  • 使用json{}[]方式进行查询
  • 默认传参:unionFormat

OneToOne

  • 表示一对一的关系
  • 通常通过外键来实现这种关系
  • 映射内容为对象

联表查询字段

序号字段信息描述默认值
1field当前表字段-
2table外键表名称
3key外键表字段id
4view映射字段(为空:默认当前表字段field,不能为id-
5nullable是否可为空(为空返回{}[]true
6type返回数据对象类型(ObjectArrayObject

完整案例

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

  • 表示一对多的关系
  • 通常通过主键来实现这种关系
  • 映射内容为数组

联表查询字段

序号字段信息描述默认值
1field当前表字段id
2table外键表名称
3key外键表字段-
4view映射字段(为空:默认当前表字段field,不能为id-
5nullable是否可为空(为空返回{}[]true
6type返回数据对象类型(ObjectArrayArray

完整案例

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

  • 表示多对多的关系
  • 通常通过中间表来实现这种关系
  • 映射内容为数组

联表查询字段

序号字段信息描述默认值
1field当前表字段id
2table外键表名称
3key外键表字段id
4view映射字段(不为空)-
5nullable是否可为空(为空返回{}[]true
6type返回数据对象类型(ObjectArrayArray
7join中间表,及外键信息

中间表字段

序号字段信息描述默认值
1field当前表字段
2table外键表名称
3key外键表字段

完整案例

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"
    }
}