0

I want to return small chunk of data on every client request. Suppose 100 item on each request. Here is my service side controller code-

  @RequestMapping(value = "/find/customerrequestv2byperiod", method = RequestMethod.GET,
  produces = "application/json")
  @ResponseBody
  public List<CustomerRequestV2> findCustomerReq(@RequestParam(value = "id") final String pId,
  @RequestParam(value = "datetperiod") final String pdatetPeriod)
  {
   List<CustomerRequestV2> requestList = null;
     try
      {
        requestList = requestService.findCustomerReq(pProductId, pReceiptPeriod);

      }
        catch (final ServiceException e)
      {
         LOG.error(ERROR_RETRIEVING_LIST + pProductId, e);
      }
       return requestList;
  }

Here requestList contains list of data matched for this query. Since sometime it retruns more than 500 data at a time. client side am using angular.js. So just wanted to send some offset value in request itself but how to return small chunk of data from here?

JOGO
  • 285
  • 2
  • 7
  • 16
  • make sublist based on offset and send.. – Dangling Piyush Feb 16 '16 at 18:23
  • Possible duplicate of [How to implement pagination in Spring MVC 3](http://stackoverflow.com/questions/2245035/how-to-implement-pagination-in-spring-mvc-3) – Dangling Piyush Feb 16 '16 at 18:26
  • try using sublist based on your requirement. Below is the link for detailed information about sublist on list. http://beginnersbook.com/2013/12/how-to-get-sublist-of-an-arraylist-with-example/ – user3509208 Feb 16 '16 at 18:27

1 Answers1

0
if(requestList == null || offset > requestList.size()) return new ArrayList<CustomerRequestV2>();

int numberOfItems = 100;
int fromIndex = offset;
int toIndex = Math.min(offset+numberOfItems, requestList.size()); 

return requestList.subList(fromIndex, toIndex);
Tin
  • 794
  • 5
  • 10