|
1 | 1 | /*
|
2 |
| - * Copyright 2013-2014 the original author or authors. |
| 2 | + * Copyright 2013-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -235,9 +235,9 @@ public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewCon
|
235 | 235 | return null;
|
236 | 236 | }
|
237 | 237 |
|
238 |
| - int page = StringUtils.hasText(pageString) ? parseAndApplyBoundaries(pageString, Integer.MAX_VALUE) |
| 238 | + int page = StringUtils.hasText(pageString) ? parseAndApplyBoundaries(pageString, Integer.MAX_VALUE, true) |
239 | 239 | : defaultOrFallback.getPageNumber();
|
240 |
| - int pageSize = StringUtils.hasText(pageSizeString) ? parseAndApplyBoundaries(pageSizeString, maxPageSize) |
| 240 | + int pageSize = StringUtils.hasText(pageSizeString) ? parseAndApplyBoundaries(pageSizeString, maxPageSize, false) |
241 | 241 | : defaultOrFallback.getPageSize();
|
242 | 242 |
|
243 | 243 | // Limit lower bound
|
@@ -302,17 +302,18 @@ private static Pageable getDefaultPageRequestFrom(MethodParameter parameter) {
|
302 | 302 | }
|
303 | 303 |
|
304 | 304 | /**
|
305 |
| - * Tries to parse the given {@link String} into an integer and applies the given boundaries. Will return the lower |
306 |
| - * boundary if the {@link String} cannot be parsed. |
| 305 | + * Tries to parse the given {@link String} into an integer and applies the given boundaries. Will return 0 if the |
| 306 | + * {@link String} cannot be parsed. |
307 | 307 | *
|
308 |
| - * @param parameter |
309 |
| - * @param upper |
| 308 | + * @param parameter the parameter value. |
| 309 | + * @param upper the upper bound to be applied. |
| 310 | + * @param shiftIndex whether to shift the index if {@link #oneIndexedParameters} is set to true. |
310 | 311 | * @return
|
311 | 312 | */
|
312 |
| - private int parseAndApplyBoundaries(String parameter, int upper) { |
| 313 | + private int parseAndApplyBoundaries(String parameter, int upper, boolean shiftIndex) { |
313 | 314 |
|
314 | 315 | try {
|
315 |
| - int parsed = Integer.parseInt(parameter) - (oneIndexedParameters ? 1 : 0); |
| 316 | + int parsed = Integer.parseInt(parameter) - (oneIndexedParameters && shiftIndex ? 1 : 0); |
316 | 317 | return parsed < 0 ? 0 : parsed > upper ? upper : parsed;
|
317 | 318 | } catch (NumberFormatException e) {
|
318 | 319 | return 0;
|
|
0 commit comments