Set default page size for JPA Pageable Object

后端 未结 8 1764
忘掉有多难
忘掉有多难 2020-12-01 09:11

I have a PagingandSorting Repository which has a method that accecpts a pageable object. I also have a controller that accepts a pageable object through the URL.

My

8条回答
  •  -上瘾入骨i
    2020-12-01 10:10

    You can use this Annotation before your Pageable param:

    @PageableDefault(size = 40)
    
    // so your parameter should be like this:
    @PageableDefault(size = 40) Pageable pageable
    

    ** Update: You can store 40 in application.yml file and use it in the whole project.

    in application.yml :

    pageSize: 40
    

    then:

    // so your parameter should be like this:
    @PageableDefault(size = ${pageSize}) Pageable pageable
    

提交回复
热议问题