在所有文档中,我找到了 ODataQueryBuilder 的示例。但是您是否也有一个示例如何使用包 com.sap.cloud.sdk.odatav2.connectivity 的 Create、Update 和 Delete 方法:
- ODataCreateRequestBuilder
- ODataDeleteRequestBuilder
- ODataUpdateRequestBuilder
CSRF 令牌是如何处理的?
请提供一个工作示例?
在所有文档中,我找到了 ODataQueryBuilder 的示例。但是您是否也有一个示例如何使用包 com.sap.cloud.sdk.odatav2.connectivity 的 Create、Update 和 Delete 方法:
CSRF 令牌是如何处理的?
请提供一个工作示例?
CSRF 令牌是通过 OData 服务的元数据端点上的 HEAD 请求获取的。
一些注意事项:
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");