2

I'd like to provide a default pagination for my method using Spring data jpa. How do I have to call the following method so that default pagination is applied? I tried passing null argument but that would lead to an unpaged list.

interface PagedRepository extends CrudRepository<User, Long> {
    @Query("SELECT u FROM user u WHERE)
    List<User> findAllPaged(@PageableDefault(size = 20));
}

//repo.findAllPaged(null);

I could pass a new Pageable myself, but that make @PageableDefault useless. repo.findAllPaged(new PageableRequest(0, 20));

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • does this may be of some help? http://stackoverflow.com/questions/10527124/how-to-query-data-via-spring-data-jpa-by-sort-and-pageable-both-out-of-box – Eugene Apr 07 '14 at 11:12
  • this will help you brother http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-seven-pagination/ – Harshal Patil Apr 07 '14 at 11:18
  • Please read the links you post before you answer. None of the links target my question "how can I use the method with @PageableDefault". As I wrote, I already know how I can pass a parameter as pageable. – membersound Apr 07 '14 at 11:42

1 Answers1

1

Use Application.properties Configuration File

you can specify the default page size globally in your configuration file with it be a yaml/toml or a properties file by setting your desired number like below :

spring.data.web.pageable.default-page-size=page-size

  • Well but I would want to set different default sizes for different query methods. This would change the settings globally. – membersound Jul 08 '22 at 08:05
  • Well in that case, you have to add variables in your properties file and use `@Value` or `@ConfigurationPropertires` in every bean you want to inject these page sizes – Elwafi Elmehdi Jul 09 '22 at 13:53