@Test(expected = IllegalStateException.class) public void testErrorSortProperty() throws Exception { int pn = 1; int pageSize = 10; request.setParameter("foo_page.pn", String.valueOf(pn)); request.setParameter("foo_page.size", String.valueOf(pageSize)); request.setParameter("foo_sort2.id$", "desc"); request.setParameter("foo_sort1.baseInfo.realname", "asc"); MethodParameter parameter = new MethodParameter(customNamePrefixPageableAndSort, 0); NativeWebRequest webRequest = new ServletWebRequest(request); Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null); }
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { PageableDefaults pageableDefaults = getPageableDefaults(parameter); Pageable defaultPageRequest = getDefaultFromAnnotationOrFallback(pageableDefaults); String pageableNamePrefix = getPagePrefix(parameter); String sortNamePrefix = getSortPrefix(parameter); Map<String, String[]> pageableMap = getPrefixParameterMap(pageableNamePrefix, webRequest, true); Map<String, String[]> sortMap = getPrefixParameterMap(sortNamePrefix, webRequest, false); Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest, webRequest); if (pageableMap.size() == 0) { return new PageRequest(defaultPageRequest.getPageNumber(), defaultPageRequest.getPageSize(), sort == null ? defaultPageRequest.getSort() : sort); } int pn = getPn(pageableMap, defaultPageRequest); int pageSize = getPageSize(pageableMap, defaultPageRequest); return new PageRequest(pn - 1, pageSize, sort); }
PageableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { PageableDefaults pageableDefaults = getPageableDefaults(parameter); Pageable defaultPageRequest = getDefaultFromAnnotationOrFallback(pageableDefaults); String pageableNamePrefix = getPagePrefix(parameter); String sortNamePrefix = getSortPrefix(parameter); Map<String, String[]> pageableMap = getPrefixParameterMap(pageableNamePrefix, webRequest, true); Map<String, String[]> sortMap = getPrefixParameterMap(sortNamePrefix, webRequest, false); Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest, webRequest); if (pageableMap.size() == 0) { return new PageRequest(defaultPageRequest.getPageNumber(), defaultPageRequest.getPageSize(), sort == null ? defaultPageRequest.getSort() : sort); } int pn = getPn(pageableMap, defaultPageRequest); int pageSize = getPageSize(pageableMap, defaultPageRequest); return new PageRequest(pn - 1, pageSize, sort); } }
PageableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { PageableDefaults pageableDefaults = getPageableDefaults(parameter); Pageable defaultPageRequest = getDefaultFromAnnotationOrFallback(pageableDefaults); String pageableNamePrefix = getPagePrefix(parameter); String sortNamePrefix = getSortPrefix(parameter); Map<String, String[]> pageableMap = getPrefixParameterMap(pageableNamePrefix, webRequest, true); Map<String, String[]> sortMap = getPrefixParameterMap(sortNamePrefix, webRequest, false); Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest, webRequest); if (pageableMap.size() == 0) { return new PageRequest(defaultPageRequest.getPageNumber(), defaultPageRequest.getPageSize(), sort == null ? defaultPageRequest.getSort() : sort); } int pn = getPn(pageableMap, defaultPageRequest); int pageSize = getPageSize(pageableMap, defaultPageRequest); return new PageRequest(pn - 1, pageSize, sort); }  }
PageableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { PageableDefaults pageableDefaults = getPageableDefaults(parameter); Pageable defaultPageRequest = getDefaultFromAnnotationOrFallback(pageableDefaults); String pageableNamePrefix = getPagePrefix(parameter); String sortNamePrefix = getSortPrefix(parameter); Map<String, String[]> pageableMap = getPrefixParameterMap(pageableNamePrefix, webRequest, true); Map<String, String[]> sortMap = getPrefixParameterMap(sortNamePrefix, webRequest, false); Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest, webRequest); if (pageableMap.size() == 0) { return new PageRequest(defaultPageRequest.getPageNumber(), defaultPageRequest.getPageSize(), sort == null ? defaultPageRequest.getSort() : sort); } int pn = getPn(pageableMap, defaultPageRequest); int pageSize = getPageSize(pageableMap, defaultPageRequest); return new PageRequest(pn - 1, pageSize, sort); }  void setMinPageSize(int minPageSize); void setMaxPageSize(int maxPageSize); void setFallbackPagable(Pageable fallbackPagable); void setPagePrefix(String pagePrefix); void setSortPrefix(String sortPrefix); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory); }
PageableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { PageableDefaults pageableDefaults = getPageableDefaults(parameter); Pageable defaultPageRequest = getDefaultFromAnnotationOrFallback(pageableDefaults); String pageableNamePrefix = getPagePrefix(parameter); String sortNamePrefix = getSortPrefix(parameter); Map<String, String[]> pageableMap = getPrefixParameterMap(pageableNamePrefix, webRequest, true); Map<String, String[]> sortMap = getPrefixParameterMap(sortNamePrefix, webRequest, false); Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest, webRequest); if (pageableMap.size() == 0) { return new PageRequest(defaultPageRequest.getPageNumber(), defaultPageRequest.getPageSize(), sort == null ? defaultPageRequest.getSort() : sort); } int pn = getPn(pageableMap, defaultPageRequest); int pageSize = getPageSize(pageableMap, defaultPageRequest); return new PageRequest(pn - 1, pageSize, sort); }  void setMinPageSize(int minPageSize); void setMaxPageSize(int maxPageSize); void setFallbackPagable(Pageable fallbackPagable); void setPagePrefix(String pagePrefix); void setSortPrefix(String sortPrefix); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory);  }