在请求主体spring boot中只传递id或整个实体

xfyts7mz  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(459)

我正试图在springboot中构建restapi,但在请求主体方面,我处于进退两难的境地。如果一个实体,例如医生有一个子实体,比如说一个专门化,我应该只传递专门化的id还是整个实体的id。
第一个案例

{

    "contractId": 1,
    "user": {
        "firstname": "",
        "lastname": "",
        "email": "",
        "phoneNumber": "",
        "username": "",
        "password": "",
        "gender": "", 
    },
    "roleId": 1,
    "specializations": [
        {
            "id": 1
        }, 
        {
            "id": 2
        }
    ],
    "qualifications": [
        {
            "id": 1
        },
        {
            "id": 2
        }
    ]
}

第二种情况

{

    "contractId": 1,
    "user": {
        "firstname": "",
        "lastname": "",
        "email": "",
        "phoneNumber": "",
        "username": "",
        "password": "",
        "gender": "", 
    },
    "roleId": 1,
    "specializations": [
        {
            "id": 1,
            "name": "Specialization_1"
        }
    ],
    "qualifications": [
        {
            "id": 1, 
            "name": "Qualification_1"
        },
        {
            "id": 2,
            "name: "Qualification_2"
        }
    ]
}
omqzjyyz

omqzjyyz1#

如果您在进行此调用之前知道id,并且id总是绑定到特定的专门化,那么是的,只有id就足够了

相关问题