4

在所有文档中,我找到了 ODataQueryBuilder 的示例。但是您是否也有一个示例如何使用包 com.sap.cloud.sdk.odatav2.connectivity 的 Create、Update 和 Delete 方法:

  • ODataCreateRequestBuilder
  • ODataDeleteRequestBuilder
  • ODataUpdateRequestBuilder

CSRF 令牌是如何处理的?

请提供一个工作示例?

4

1 回答 1

1

CSRF 令牌是通过 OData 服务的元数据端点上的 HEAD 请求获取的。

一些注意事项:

  • 以下示例假定您在 SAP Cloud Platform 主控室中配置了一个名为“DestinationName”的目标。
  • 请记住,S/4HANA 虚拟数据模型通常是更简单的选择。

ODataCreateRequestBuilder

Map<String, Object> body = new HashMap<>();
body.put("FirstName", "John");
body.put("LastName", "Doe");
body.put("BusinessPartnerCategory", "1");

ODataCreateRequest createRequest =
    ODataCreateRequestBuilder
        .withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartner")
        .withBodyAsMap(body)
        .build();

createRequest.execute("DestinationName");                 

ODataUpdateRequestBuilder

Map<String, Object> keys = new HashMap<>();
keys.put("BusinessPartner", "12345");

Map<String, Object> params = new HashMap<>();
params.put("FirstName", "John");
params.put("MiddleName", "D.");
params.put("LastName", "Doe");
params.put("BusinessPartnerCategory", "1");

final ODataUpdateRequest updateRequest =
    ODataUpdateRequestBuilder
        .withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartner", keys)
        .withBodyAsMap(params)
        .build();

updateRequest.execute("DestinationName");      

ODataDeleteRequestBuilder

Map<String, Object> keys = new HashMap<>();
keys.put("BusinessPartner", "12345");
keys.put("AddressID", "98765");

ODataDeleteRequest deleteRequest =
    ODataDeleteRequestBuilder
        .withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartnerAddress", keys)
        .build();

deleteRequest.execute("DestinationName");
于 2018-02-22T17:34:42.533 回答