将多个对象链接到HttpEntity

时间:2016-07-21 13:10:30

标签: java request resttemplate httpentity

我的休息api使用带有2个对象参数的POST请求:自定义类型和长

enter image description here

我可以将一个参数链接到body,如下所示:

private void createCaseParticipant(long caseId, CaseParticipantDTO caseParticipantDTO)
    {
        HttpHeaders headers = new HttpHeaders();
        headers.add(AUTHORIZATION_HEADER_NAME, BASIC_AUTHORIZATION_HEADER_PREFIX + cmsRestApiCreds);

        HttpEntity<CaseParticipantDTO> postRequest = new HttpEntity<CaseParticipantDTO>(caseParticipantDTO, headers);
    }

如何在我的请求中添加第二个参数? 谢谢

1 个答案:

答案 0 :(得分:1)

你只需将它添加到HttpHeadersobjects就像这样:

private void createCaseParticipant(long caseId, CaseParticipantDTO caseParticipantDTO)
    {
        HttpHeaders headers = new HttpHeaders();
        headers.add(AUTHORIZATION_HEADER_NAME, BASIC_AUTHORIZATION_HEADER_PREFIX + cmsRestApiCreds);
        headers.add("caseId",caseId.toString());
        headers.add("caseParticipantDTO", caseParticipantDTO.toString());
        HttpEntity<CaseParticipantDTO> postRequest = new HttpEntity<CaseParticipantDTO>(caseParticipantDTO, headers);
    }