简体   繁体   中英

Moqui Framework To Call Rest Service for "Age" between From And To:

I've implemented an application using Moqui Framework.I have a field named as "age" in entity.I am trying to get all record from entity where the age between 20 to 25. How to create rest service in order to get the given age between & How to specify the url for this requirement. This is the url:rest/s1/UserMargen/DetailsOfUser And i am getting as

{
    "street": "Bridege",
    "age": 22,
    "city": "kol",
    "username": "Debendu",
    "lastUpdatedStamp": "2016-04-26T12:43:45+0000",
    "userid": "2000"
},
{
    "lastUpdatedStamp": "2016-04-26T12:42:42+0000",
    "userid": "2001",
    "street": "White",
    "username": "rolla",
    "city": "Ban",
    "age": 20
},
{
    "username": "Venkatesh",
    "street": "T-nager",
    "age": 28,
    "userid": "2005",
    "city": "chennai",
    "lastUpdatedStamp": "2016-04-26T12:48:33+0000"
} 

In rest.xml I have Defined as

<resource name="DetailsOfUser" >
    <method type="get"><entity name="UserInDetails" operation="list"/></method>
    <method type="post"><service name="UserMargen.UserMargenServices.create#userDetails"/></method>

    <id name="age">
        <method type="get"><entity name="UserInDetails" operation="list"/></method>
    </id></resource> 

If i give /rest/s1/UserMargen/DetailsOfUser/22 it will display which age equals 22. How to get records in between age from 20 to 25 ?

In XML REST API definitions in Moqui Framework the method.entity element behaves the same as for the entity (/rest/e1) and entity master (/rest/m1) interfaces, which behave the same as the search form inputs (either in a XML Screen file or through the EntityFind interface). For search form inputs you can use the field name plus "_from" and "_thru" suffixes to do a ranged find on numeric or date/time fields.

If you want the age range values to be in the URL as path parameters you'll need to define an id element with the name age_from and another id element under it with the name age_thru. A more flexible approach would just be to pass them as URL parameters instead of path elements, ie something like:

/rest/s1/UserMargen/DetailsOfUser?age_from=20&age_thru=25

Using this pattern you can pass field values or any of the suffixes supported by EntityFind.searchFormInputs()/searchFormMap(): _op, _not, _ic, _period/_poffset, _from, and _thru. You can also pass an orderByField parameter which can be a comma-separated list of field names. You can also pass pagination parameters like pageIndex, pageSize, or even pageNoLimit to not paginate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM