zoukankan      html  css  js  c++  java
  • oData

    An open protocol to allow the creation and consumption of queryable and interoperable RESTful APIs in a simple and standard way.

    开放数据协议(OData)是一个查询和更新数据的Web协议。OData应用了web技术如HTTP、Atom发布协议(AtomPub)和JSON等来提供对不同应用程序,服务和存储的信息访问。除了提供一些基本的操作(像增删改查),也提供了一些高级的操作类似过滤数据和实体的导航。OData扩展了上述的协议但是不是取代他们。他可以被XML(ATOM)或者JSON取代但是OData的重要在于它符合REST原则。在某种意义上,它建立在'简单'的REST HTTP 服务上,并且有着清晰的目标——简化和标准化我们操作和查询数据的方式。如果你过去在给你的REST服务创建搜索、过滤、或者分页API的时候感觉很麻烦,那么OData将是一个不错的选择。

    接口调用说明:

    下表列举了一些常用的Odata操作:

    操作

    URL

    说明

                 $filter http://localhost:8090/api/Meetings?$filter=ProductName eq 'Tofu' 根据表达式的状态返回结果(返回ProductName 等于Tofu的Products)
                $orderby http://localhost:8090/api/Meetings?$orderby=ProductName 根据结果排序(根据ProductName列排序)
                $skip http://localhost:8090/api/Meetings?$skip=10 越过结果中的n条数据,常用于分页
                $top http://localhost:8090/api/Meetings?$top=10 返回结果中的前n条记录,常用于分页
               $select http://localhost:8090/api/Meetings?$filter=ProductName eq 'Tofu'&$select=ProductName,UnitPrice 选择需要返回的属性
               $expand http://localhost:8090/api/Meetings?$expand=Supplier 返回Products中包含的导航属性(关联属性)Supplier
              $inlinecount http://localhost:8090/api/Meetings?$inlinecount=allpages 向服务器获取符合条件的资源总数(分页的total值)

    通过上面表格的内容,我们还可以通过组合查询条件来实现复杂的查询。

    常用查询举例:

      示例1:列出所有Product
      URL:http://localhost:8914/Products

       示例2,查询Products,只列出Name,Price例
      URL:http://localhost:8914/Products?$select=Name,Price

      示例3:列出Products(只有列Name,Price),包括Supplier
      URL:http://localhost:8914/Products?$select=Name,Price&$expand=Supplier

      示例4:过滤Products,只显示分类为Test的数据
      URL:http://localhost:8914/Products?$filter=Category eq ’Test‘

      示例5:过滤Products,只显示分类为Test的数据,并排序
      URL:http://localhost:8914/Products?$filter=Category eq ’Test‘&$orderby=Price desc

      $filter的其它的使用方式:

      1.  http://localhost/Products?$filter=Category eq 'Test'
        过滤Category=Test
      2.http://localhost/Products?$filter=Price lt 10
        过滤Price小于10
      3.http://localhost/Products?$filter=Price ge 5 and Price le 15
        过滤5<=Price>=15
      4.还可以使用数据库函数如:
        $filter=substringof('zz',Name)
        $filter=year(ReleaseDate) gt 2005

      5.关于排序:
        $orderby=Price
        $orderby=Price desc
        $orderby=Category,Price desc

      6.还有一些过滤器如:
        $skip,$top,$inlinecount等等

  • 相关阅读:
    【邀请函】小投入 大产出—微软智能云(Azure)之CDN 专题
    Azure镜像市场再下一城,中标软件入驻开启Azure国产操作系统时代
    15分钟完成基于Azure公有云搭建远程测试环境
    独家秘笈!教你解锁移动应用新技能
    “剁手节”来了,红包你抢到了吗?
    Azure 11 月新公布
    面对故宫万千珍宝,升哲科技如何做到“朕知道了”
    高斯-克吕格投影
    cad定制快捷键
    matlab之scatter3()与plot3()函数
  • 原文地址:https://www.cnblogs.com/ellie-test/p/7027462.html
Copyright © 2011-2022 走看看