Issue
I'm using Spring-Boot 2.1.6 and I have a Rest Controller that allows for pagination using spring-data's Pageable
interface. When I issue a request, defining pagination parameters that are different from the pagination defaults e.g. http://localhost:8080/tasks?size=100&page=0
from an Angular application using Number.MAX_SAFE_INTEGER
for the size parameter, I get back 10 tasks (same as the default size
in @PageableDefault
) even though I've requested 200. And yes, I do have more than 10 tasks
@RestController
@RequestMapping("/tasks")
class TasksController(
private val taskService: TasksService,
private val tasksRepository: TasksRepository
) {
@GetMapping
fun list(
@RequestParam(required = false) state: TaskState?,
@PageableDefault pageable: Pageable
): Page<Task> =
return tasksRepository.findByState(state, pageable)
Solution
It turn out the problem was self-inflicted. Number.MAX_SAFE_INTEGER
results in 9,007,199,254,740,991
, which is way bigger than Java's Integer.MAX
value (2,147,483,648
) and the Pageable
interface uses int
as the type for size
.
Answered By - Fana Sithole