diff --git a/src/main/java/org/springframework/data/web/PageableHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/PageableHandlerMethodArgumentResolver.java index d9d0ecba59..a14faf616a 100644 --- a/src/main/java/org/springframework/data/web/PageableHandlerMethodArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/PageableHandlerMethodArgumentResolver.java @@ -83,15 +83,12 @@ public Pageable resolveArgument(MethodParameter methodParameter, @Nullable Model Sort sort = sortResolver.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory); Pageable pageable = getPageable(methodParameter, page, pageSize); - if (sort.isSorted()) { - if (pageable.isPaged()) { - pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); - } - else { - pageable = Pageable.unpaged(sort); - } + if (!sort.isSorted()) { + return pageable; } - return pageable; + return pageable.isPaged() + ? PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort) + : Pageable.unpaged(sort); } } diff --git a/src/main/java/org/springframework/data/web/ReactivePageableHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/ReactivePageableHandlerMethodArgumentResolver.java index 9b8f710cc9..438e83e0dc 100644 --- a/src/main/java/org/springframework/data/web/ReactivePageableHandlerMethodArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/ReactivePageableHandlerMethodArgumentResolver.java @@ -78,15 +78,12 @@ public Pageable resolveArgumentValue(MethodParameter parameter, BindingContext b Sort sort = sortResolver.resolveArgumentValue(parameter, bindingContext, exchange); Pageable pageable = getPageable(parameter, page, pageSize); - if (sort.isSorted()) { - if (pageable.isPaged()) { - pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); - } - else { - pageable = Pageable.unpaged(sort); - } + if (!sort.isSorted()) { + return pageable; } - return pageable; + return pageable.isPaged() + ? PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort) + : Pageable.unpaged(sort); } }