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

前端 未结 2 784
暗喜
暗喜 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> 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.

提交回复
热议问题