0

我正在使用来自https://github.com/mulesoft/apikit-odata-example的 odata 示例。

当我包含 inlinecount 过滤器(请参阅下面的请求)时,计数不会随结果一起返回。如何将计数添加到响应中?

请求:http://localhost:8081/api/odata.svc/customers ?$format=json&$inlinecount=allpages

回复:

{
 "d": {
     "results": [
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Alfreds Futterkiste",
             "ContactName": "Maria Anders",
             "ContactTitle": "Sales Representative",
             "CustomerID": ""
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('ALFKI')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Alfreds Futterkiste",
             "ContactName": "Maria Anders",
             "ContactTitle": "Sales Representative",
             "CustomerID": "ALFKI"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('ANATR')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Ana Trujillo Emparedados y helados",
             "ContactName": "Ana Trujillo",
             "ContactTitle": "Owner",
             "CustomerID": "ANATR"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('ANTON')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Antonio Moreno Taquera",
             "ContactName": "Antonio Moreno",
             "ContactTitle": "Owner",
             "CustomerID": "ANTON"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('AROUT')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Around the Horn",
             "ContactName": "Thomas Hardy",
             "ContactTitle": "Sales Representative",
             "CustomerID": "AROUT"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BERGS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Berglunds snabbkp",
             "ContactName": "Christina Berglund",
             "ContactTitle": "Order Administrator",
             "CustomerID": "BERGS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BLAUS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Blauer See Delikatessen",
             "ContactName": "Hanna Moos",
             "ContactTitle": "Sales Representative",
             "CustomerID": "BLAUS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BLONP')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Blondesddsl pre et fils",
             "ContactName": "Frdrique Citeaux",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "BLONP"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BOLID')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Blido Comidas preparadas",
             "ContactName": "Martn Sommer",
             "ContactTitle": "Owner",
             "CustomerID": "BOLID"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BONAP')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Bon app'",
             "ContactName": "Laurence Lebihan",
             "ContactTitle": "Owner",
             "CustomerID": "BONAP"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BOTTM')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Bottom-Dollar Markets",
             "ContactName": "Elizabeth Lincoln",
             "ContactTitle": "Accounting Manager",
             "CustomerID": "BOTTM"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('BSBEV')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "B's Beverages",
             "ContactName": "Victoria Ashworth",
             "ContactTitle": "Sales Representative",
             "CustomerID": "BSBEV"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('CACTU')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Cactus Comidas para llevar",
             "ContactName": "Patricio Simpson",
             "ContactTitle": "Sales Agent",
             "CustomerID": "CACTU"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('CENTC')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Centro comercial Moctezuma",
             "ContactName": "Francisco Chang",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "CENTC"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('CHOPS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Chop-suey Chinese",
             "ContactName": "Yang Wang",
             "ContactTitle": "Owner",
             "CustomerID": "CHOPS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('COMMI')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Comrcio Mineiro",
             "ContactName": "Pedro Afonso",
             "ContactTitle": "Sales Associate",
             "CustomerID": "COMMI"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('CONSH')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Consolidated Holdings",
             "ContactName": "Elizabeth Brown",
             "ContactTitle": "Sales Representative",
             "CustomerID": "CONSH"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('DRACD')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Drachenblut Delikatessen",
             "ContactName": "Sven Ottlieb",
             "ContactTitle": "Order Administrator",
             "CustomerID": "DRACD"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('DUMON')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Du monde entier",
             "ContactName": "Janine Labrune",
             "ContactTitle": "Owner",
             "CustomerID": "DUMON"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('EASTC')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Eastern Connection",
             "ContactName": "Ann Devon",
             "ContactTitle": "Sales Agent",
             "CustomerID": "EASTC"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('ERNSH')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Ernst Handel",
             "ContactName": "Roland Mendel",
             "ContactTitle": "Sales Manager",
             "CustomerID": "ERNSH"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FAMIA')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Familia Arquibaldo",
             "ContactName": "Aria Cruz",
             "ContactTitle": "Marketing Assistant",
             "CustomerID": "FAMIA"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FANT')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Fantasma",
             "ContactName": "Casper",
             "ContactTitle": "Evasor Profesional",
             "CustomerID": "FANT"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FISSA')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "FISSA Fabrica Inter. Salchichas S.A.",
             "ContactName": "Diego Roel",
             "ContactTitle": "Accounting Manager",
             "CustomerID": "FISSA"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FOLIG')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Folies gourmandes",
             "ContactName": "Martine Ranc",
             "ContactTitle": "Assistant Sales Agent",
             "CustomerID": "FOLIG"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FOLKO')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Folk och f HB",
             "ContactName": "Maria Larsson",
             "ContactTitle": "Owner",
             "CustomerID": "FOLKO"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FRANK')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Frankenversand",
             "ContactName": "Peter Franken",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "FRANK"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FRANR')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "France restauration",
             "ContactName": "Carine Schmitt",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "FRANR"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FRANS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Franchi S.p.A.",
             "ContactName": "Paolo Accorti",
             "ContactTitle": "Sales Representative",
             "CustomerID": "FRANS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('FURIB')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Furia Bacalhau e Frutos do Mar",
             "ContactName": "Lino Rodriguez",
             "ContactTitle": "Sales Manager",
             "CustomerID": "FURIB"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('GALED')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Galera del gastrnomo",
             "ContactName": "Eduardo Saavedra",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "GALED"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('GODOS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Godos Cocina Tpica",
             "ContactName": "Jos Pedro Freyre",
             "ContactTitle": "Sales Manager",
             "CustomerID": "GODOS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('GOURL')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Gourmet Lanchonetes",
             "ContactName": "Andr Fonseca",
             "ContactTitle": "Sales Associate",
             "CustomerID": "GOURL"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('GREAL')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Great Lakes Food Market",
             "ContactName": "Howard Snyder",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "GREAL"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('GROSR')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "GROSELLA-Restaurante",
             "ContactName": "Manuel Pereira",
             "ContactTitle": "Owner",
             "CustomerID": "GROSR"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('HANAR')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Hanari Carnes",
             "ContactName": "Mario Pontes",
             "ContactTitle": "Accounting Manager",
             "CustomerID": "HANAR"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('HILAA')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "HILARION-Abastos",
             "ContactName": "Carlos Hernndez",
             "ContactTitle": "Sales Representative",
             "CustomerID": "HILAA"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('HUNGC')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Hungry Coyote Import Store",
             "ContactName": "Yoshi Latimer",
             "ContactTitle": "Sales Representative",
             "CustomerID": "HUNGC"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('HUNGO')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Hungry Owl All-Night Grocers",
             "ContactName": "Patricia McKenna",
             "ContactTitle": "Sales Associate",
             "CustomerID": "HUNGO"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('ISLAT')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Island Trading",
             "ContactName": "Helen Bennett",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "ISLAT"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('KOENE')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Kniglich Essen",
             "ContactName": "Philip Cramer",
             "ContactTitle": "Sales Associate",
             "CustomerID": "KOENE"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LACOR')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "La corne d'abondance",
             "ContactName": "Daniel Tonini",
             "ContactTitle": "Sales Representative",
             "CustomerID": "LACOR"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LAMAI')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "La maison d'Asie",
             "ContactName": "Annette Roulet",
             "ContactTitle": "Sales Manager",
             "CustomerID": "LAMAI"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LAUGB')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Laughing Bacchus Wine Cellars",
             "ContactName": "Yoshi Tannamuri",
             "ContactTitle": "Marketing Assistant",
             "CustomerID": "LAUGB"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LAZYK')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Lazy K Kountry Store",
             "ContactName": "John Steel",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "LAZYK"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LEHMS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Lehmanns Marktstand",
             "ContactName": "Renate Messner",
             "ContactTitle": "Sales Representative",
             "CustomerID": "LEHMS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LETSS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Let's Stop N Shop",
             "ContactName": "Jaime Yorres",
             "ContactTitle": "Owner",
             "CustomerID": "LETSS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LILAS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "LILA-Supermercado",
             "ContactName": "Carlos Gonzlez",
             "ContactTitle": "Accounting Manager",
             "CustomerID": "LILAS"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LINOD')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "LINO-Delicateses",
             "ContactName": "Felipe Izquierdo",
             "ContactTitle": "Owner",
             "CustomerID": "LINOD"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('LONEP')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Lonesome Pine Restaurant",
             "ContactName": "Fran Wilson",
             "ContactTitle": "Sales Manager",
             "CustomerID": "LONEP"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('MAGAA')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Magazzini Alimentari Riuniti",
             "ContactName": "Giovanni Rovelli",
             "ContactTitle": "Marketing Manager",
             "CustomerID": "MAGAA"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('MAISD')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Maison Dewey",
             "ContactName": "Catherine Dewey",
             "ContactTitle": "Sales Agent",
             "CustomerID": "MAISD"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('MEREP')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Mre Paillarde",
             "ContactName": "Jean Fresnire",
             "ContactTitle": "Marketing Assistant",
             "CustomerID": "MEREP"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('MORGK')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "Morgenstern Gesundkost",
             "ContactName": "Alexander Feuer",
             "ContactTitle": "Marketing Assistant",
             "CustomerID": "MORGK"
         },
         {
             "__metadata": {
                 "uri": "http://localhost:8081/api/odata.svc/customers('NORTS')",
                 "type": "odata2.namespace.customers"
             },
             "CompanyName": "North/South",
             "ContactName": "Simon Crowther",
             "ContactTitle": "Sales Associate",
             "CustomerID": "NORTS"
         }
         ...
     ]
 }

}

4

1 回答 1

0

您需要更新 odata.raml 文件。就像任何其他 Mulesoft 项目一样,它的实现将填充符合您提供给消费者的合同定义的有效负载。

在 odata.raml 中更新 RAML 类型后,您需要进入 api.xml(Mule 配置文件)并更新填充数据的 mule 流。您将简单地计算从数据库查询返回的记录并相应地填充您的有效负载以匹配数据类型,或者您可以运行数据库计数查询让数据库进行计数工作。归根结底,您的方法将基于您的系统及其可能具有的需求。

于 2018-02-11T14:50:18.330 回答