Results 1 to 1 of 1

Thread: ThreadLocal Pagination to help keep layers api clean from pagination

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default ThreadLocal Pagination to help keep layers api clean from pagination

    So, I created a class called PageRequestHandler that will allow me to pass the page and size information for pagination that comes in to my Controller's URL, then access it in a lower layer to pass to my Spring Data Repository.

    Here is the code.

    https://gist.github.com/3718376

    It is just missing storing Sort information to be 100% Spring Data supported.

    Here is the code I would have in my Controller

    Code:
    @RequestMapping("/search/{searchCriteria}/{page}/{size}")
        public @ResponseBody ListOfDomains<Event> searchEvents(@PathVariable("searchCriteria") String searchCriteria,
                                                 @PathVariable("page") int page,
                                                 @PathVariable("size") int size) {
            PageRequestHandler.setPageRequest(page, size);
            return eventService.searchEvents(searchCriteria);
        }
    Then in my Service, which is where I need to get it to pass to my Spring Data Repository

    Code:
    @Override
        public ListOfDomains<Event> findAllEventsByVisibility(EventVisibility visibility) {
            ListOfDomains<Event> events = new ListOfDomains<Event>(
                    eventRepository.findByVisibility(visibility.name(),
                            PageRequestHandler.getPageRequest()),
                    EventDivsTitleAndRelationships.PUBLIC_EVENTS);
            return events;
        }
    Mark
    Last edited by bytor99999; Sep 13th, 2012 at 06:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •