java - How to design a class for REST api and pagination, and hiding the internal DB? -


maybe i'm thinking wrong. trying figure out how pagination rest api.

say have data database has tables animals cats , dogs , have owners labeled

 ------          --------       -------- |cts   |         |dgs   |       | ownr | |----- |         |------|       |------| |c_id  |         |d_id  |       |id    | |c_nme |         |own_id|       |nm    | |own_id|         |d_nme |       --------  -------         |d_bn  |                  -------- 

i using hibernate , want provide rest service @ "/owners" display owner information pets. mean need return json object both human readable, , has page data.

{ "data":[  {"owner":"joe", "cats_name": "whiskers", "dogs_name": "fido"},  {"owner":"julie", "cats_name": "furry", "dogs_name": "buster"}  ],  "page_data":{"page":"2", "total_pages": "12"}} 

i retrieve data db, map results new rest class can display owner data in human readable way, while being able deal pagination because there can hundreds of thousands of owners.

public class restowner{   private string owner;   private string cats_name;   private string dogs_name; } 

now how can wrap restowner class in class page data can display rest api how need (display owners per page, along current page , total pages). wish if want display service @ "/dogs" won't need create whole new page wrapper specific dogs class well. have follows:

public class restdata{  private list <pagedata> pagedata;  private list<data> data; } 

so can replace data whatever type of object want, whether want list list of owners or list of dogs...and don't need make separate class each type of data want display

i not sure if way pagination rest api or on wrong track, , should concerned db info, , track pages different way. please me understand best way build rest api pagination ability handle large db queries. thanks!


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -