Override Pageable max page size at controller level

I need to change the max page size for an specific mapping but the only way I know to do this is changing the spring.data.web/rest.max-page-size on the properties file.

But I need to change it only for an specific endpoint without affecting others.

Is there anyway to override this parameter?

Upvotes: 5

Views: 2343

Answers (3)

Md.Habibur Rahman
Md.Habibur Rahman

Reputation: 351

for me (using spring boot version- 2.5.8) this worked- spring.data.rest.max-page-size=2147483647 not spring.data.web.max-page-size

Upvotes: -1

Olavi Vaino
Olavi Vaino

Reputation: 451

One workaround would be to override Pageable object. Its pageSize property can't be overwritten but its possible to construct new object like this

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;    
Pageable ovrPageable = PageRequest.of(pageable.getPageNumber(), MAX_PAGE_SIZE, pageable.getSort());

and then use ovrPageable instead of pageable.

Upvotes: 0

This answer helps me You need to delete spring.data.web/rest.max-page-size property and use @PageableLimits with params in endpoints

Upvotes: 3

Related Questions