Pagination on select query metamug

2019-06-04 10:10发布

This is my current resource file. I'm using MySQL Query Pagination Feature

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns="http://xml.metamug.net/resource/1.0" v="1.0">
<Request method="GET">
    <Query>
        select * from tbl_task_master 
        LIMIT $limit OFFSET $offset
    </Query>
</Request>
</Resource>

https://api.metamug.com/checklist/v1.0/task?offset=0&limit=50

It's fetching all the records. I want to paginate and only get a subset. How do I make the request with Metamug.

1条回答
▲ chillily
2楼-- · 2019-06-04 10:40

To implement pagination you need to make use of limit and offset attributes of Query tag and then you can pass it any parameter name that you'll be using in your request.
Let's say your pagination parameters are l and o for limit and offset respectively (though not a good naming convention)
Your resource file will now look like

UPDATE:

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns="http://xml.metamug.net/resource/1.0" v="1.0">
<Request method="GET">
<Param name="l" type="number" required="true" min="5" max="20"/>
<Param name="o" type="number" required="true" min="0" max="100"/>
    <Query limit="l" offset="o">
        select * from tbl_task_master 
    </Query>
</Request>
</Resource>  

Declaring

<Param name="l" type="number" required="true" min="5" max="20"/>
<Param name="o" type="number" required="true" min="0" max="100"/>  

Is optional but as you can see we can add more constraints we do initialize them.See this for more on Param tag and validation

查看更多
登录 后发表回答