外部对ODATA基本的操作就是CREATE,DELETE,UPDATA,READ,,而对于WEB来说,对应的分别是,POST,DELETE,PUT,GET三个方法,
When discussing data access, people typically talk about CRUD or
CRUD -Q (“Q” is for query) and indicate the operation to be executed.
( Que ry is a kind of Read operation and therefore the “Q” isn’t always
mentioned explicitly.) As already described in Section 2.1.1, OData uses
the REST commands P OS T, GET , PU T, or DELE TE , which map to CRUD. The OData protocol defines conventions for all of these CRUD operations,
but it’s not mandatory for every OData service to support all four oper-
ations. In this section, we’ll explain each operation and give some con-
text for their use.
一、CREATE
操作时,使用POST提交 业务参数,提交后,
调用ODATA 中***_DPC_EXT类,的***CREATE_ENTITY方法,
操作成功HTTP状态返回:201(CREATE), 类的代码可参考:基于gateway实现odata(9)–Create Methods
The Create operation is used whenever you want to create data on the POST
backend server. This is data that wasn’t present before, for exampl e, a
new sales order or a new business partner. The related HTTP method is
P OST . If the Create operation is successful, you receive the H TTP 20 1 (cre-
ated) response code, along with t he entity that was created. Via the
metadata, you can specify whether an entity set is creatable or not . This
information is reflected in the metadata document and allows the con-
sumer to act accordingly (e.g., if the application is of the type Pl aye r).
Bu t there is no default handling of this annotation by the framework;
instead, the service imp lementation has to handle it according to the
metadata definition (see Chapter 5 and Chapter 6 for more details about
service implementation).
二、READ
ODATA的读取涉及到两个方法,一个是单条读取的,一个是多行读取的,
读取如/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1002′)时,只读取主键一行数据,需要定义中***_DPC_EXT类,的ZTSALE_HSET_get_entity方法
读取如/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H时,读取多行数据,需要定义中***_DPC_EXT类,的ZTSALE_HSET_get_entityset方法,方法中的代码可参考:基于gateway实现odata(4)–查询选项1-$select
读取成功后HTTP状态返回200 (OK),
The Read operation is the most frequently used operation. Typically, GET
applications primarily read data instead of updating data- for example,
a lunch menu application that doesn’t include any option to provide
feedback about the menu provided. This data can be of any kind, such as
customizing, master data, transaction data, and so on. The related HTTP
method for the Read operation is G ET . A successful Read operation has
the HTTP 200 ( OK status code.
Read operations can be classified into two different kinds: Query and
Si ngl e Read .
三、Update
HTTP操作时,使用PUT方法提交数据,调用ODATA的类方法,
操作成功后HTTP状态返回HTTP 204 (no content )
The Update operation is used whenever you want to change an existing
entity. As such, you have to provide the same key information as in the
Si ngl e Read operation, explained earlier, to uniquely identify the entity
you want to update.
The HTTP method for the Update operation is PUT . If the U pdate opera-
tion is successful, you receive the HTTP 204 (no content l status. You’re
intentionally not getting the entity back as part of the HTTP request
because the consumer typically knows the current state of the entity,
and therefore the SAP Gateway server doesn’t need to send it back.
Instead of P UT , it’s possible to leverage the PATCH operation that allows
you to perform a partial update. The ATCH meth od is supported by the
framework and first calls the GETDE TAIL method to r etr ieve all properties
that won ‘t be updated, then merges those values with the ones that are
sent via the PATC H request, and finally performs an update using the
standard update method of an entity set.
四、DeleteHTTP操作时,使用DELETE方法提交数据,调用ODATA的类方法,
操作成功后HTTP状态返回HTTP 204 (no content )
Finally, the De l ete operation is used whenever you want to delete an
entity. Equal to the Update operation, you have to provide the primary
key of the entity you want to erase. The related HTTP method is DELETE .
A successful De l ete operation has the HTTP 204 (no content) status code.
Via the sap:de leta b le annotation, you can specify whether entities of
an entity set can be deleted or not. As before, the service implementa-
tion has to make sure that the actual operations are in line with themetadata definition (see Chapter 5 and Chapter 6 for more details about
service implementation).