spring data jpa limit pagesize, how to set to maxSize

后端 未结 12 2494
自闭症患者
自闭症患者 2020-12-15 20:09

I have one requirement is to search by pageable and non-pageable,

and in my Java code, I use spring data jpa Pageable class,

 Pageable pageable = new         


        
12条回答
  •  [愿得一人]
    2020-12-15 20:45

    This works for me:

    All pageable request use MyCustomPage and use a default page and size if not found in request.

    If size (number of record exceed the max value) i set a default value, which in this case 50.

    public class MyCustomPage extends PageRequest{
        Integer MAX_PAGE_SIZE = 50
        //constructor 
        public MyCustomPage(Integer page, Integer size) {
            super(page,(size>MAX_PAGE_SIZE)?MAX_PAGE_SIZE:size);
        }
    }
    

提交回复
热议问题