Pageable in spring for paging on List<Object> is not working

前端 未结 2 783
暗喜
暗喜 2021-01-29 13:45

I have a list of object which contain 10000 records i am trying to split that records in each of 10,

But somehow it is not working.. can someone have a look



        
相关标签:
2条回答
  • 2021-01-29 14:16

    Page just represents one page of data . So page.getContent() only return all data in one page which is specified through constructor when you create this page instance . It has nothing to do with splitting the data in a page.

    If you want to split a list , use Lists from Guava is the simplest way to go :

    List<List<Object>> splittedList = Lists.partition(list, 10);
    

    If you want to do pagination which split all the data stored in the database into different smaller pages , split it at the database level rather than getting the whole list to the memory to split which will be very inefficient when the entire list is large. See this for how to split it at the database level by declaring Pageable in the query method.

    0 讨论(0)
  • 2021-01-29 14:41

    We can use PagedListHolder which can change the list in pages and we can than fetch a page by setting it's page size and page.

    PagedListHolder<Object> page = new PagedListHolder(admin_viewapplicationpage);
          page.setPageSize(50); // number of items per page
          page.setPage(0);      // set to first page
    
          int totalPages = page.getPageCount(); //  gives the totalpages according to the main list
          
          List<Object> admin_viewapplication = page.getPageList();  // a List which represents the current page which is the sublist
          
    
    0 讨论(0)
提交回复
热议问题