@Test public void testSearchableAndNoPageAndNoSort() throws Exception { int pn = 1; int pageSize = 10; request.setParameter("page.pn", String.valueOf(pn)); request.setParameter("page.size", String.valueOf(pageSize)); request.setParameter("sort1.baseInfo.realname", "asc"); request.setParameter("sort2.id", "desc"); request.setParameter("search.baseInfo.realname_like", "zhang"); request.setParameter("search.username_eq", "zhang"); MethodParameter parameter = new MethodParameter(searchableAndNoPageAndNoSort, 0); NativeWebRequest webRequest = new ServletWebRequest(request); Searchable searchable = (Searchable) new SearchableMethodArgumentResolver().resolveArgument(parameter, null, webRequest, null); assertEquals(null, searchable.getPage()); assertEquals(null, searchable.getSort()); assertContainsSearchFilter(SearchFilterHelper.newCondition("baseInfo.realname", SearchOperator.like, "zhang"), searchable); assertContainsSearchFilter(SearchFilterHelper.newCondition("username", SearchOperator.eq, "zhang"), searchable); }
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { String searchPrefix = getSearchPrefix(parameter); Map<String, String[]> searcheableMap = getPrefixParameterMap(searchPrefix, webRequest, true); boolean hasCustomSearchFilter = searcheableMap.size() > 0; SearchableDefaults searchDefaults = getSearchableDefaults(parameter); boolean needMergeDefault = searchDefaults != null && searchDefaults.merge(); Searchable searchable = null; if (needMergeDefault || !hasCustomSearchFilter) { searchable = getDefaultFromAnnotation(searchDefaults); } if (hasCustomSearchFilter) { if (searchable == null) { searchable = Searchable.newSearchable(); } for (String name : searcheableMap.keySet()) { String[] mapValues = filterSearchValues(searcheableMap.get(name)); if (mapValues.length == 1) { if (name.endsWith("in")) { searchable.addSearchParam(name, StringUtils.split(mapValues[0], ",; ")); } else { searchable.addSearchParam(name, mapValues[0]); } } else { searchable.addSearchParam(name, mapValues); } } } Pageable pageable = (Pageable) pageableMethodArgumentResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); if (searchDefaults == null) { searchable.setPage(pageable); } if (searchDefaults != null && searchDefaults.needPage()) { searchable.setPage(pageable); } if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) { searchable.addSort(pageable.getSort()); } return searchable; }
SearchableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { String searchPrefix = getSearchPrefix(parameter); Map<String, String[]> searcheableMap = getPrefixParameterMap(searchPrefix, webRequest, true); boolean hasCustomSearchFilter = searcheableMap.size() > 0; SearchableDefaults searchDefaults = getSearchableDefaults(parameter); boolean needMergeDefault = searchDefaults != null && searchDefaults.merge(); Searchable searchable = null; if (needMergeDefault || !hasCustomSearchFilter) { searchable = getDefaultFromAnnotation(searchDefaults); } if (hasCustomSearchFilter) { if (searchable == null) { searchable = Searchable.newSearchable(); } for (String name : searcheableMap.keySet()) { String[] mapValues = filterSearchValues(searcheableMap.get(name)); if (mapValues.length == 1) { if (name.endsWith("in")) { searchable.addSearchParam(name, StringUtils.split(mapValues[0], ",; ")); } else { searchable.addSearchParam(name, mapValues[0]); } } else { searchable.addSearchParam(name, mapValues); } } } Pageable pageable = (Pageable) pageableMethodArgumentResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); if (searchDefaults == null) { searchable.setPage(pageable); } if (searchDefaults != null && searchDefaults.needPage()) { searchable.setPage(pageable); } if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) { searchable.addSort(pageable.getSort()); } return searchable; } }
SearchableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { String searchPrefix = getSearchPrefix(parameter); Map<String, String[]> searcheableMap = getPrefixParameterMap(searchPrefix, webRequest, true); boolean hasCustomSearchFilter = searcheableMap.size() > 0; SearchableDefaults searchDefaults = getSearchableDefaults(parameter); boolean needMergeDefault = searchDefaults != null && searchDefaults.merge(); Searchable searchable = null; if (needMergeDefault || !hasCustomSearchFilter) { searchable = getDefaultFromAnnotation(searchDefaults); } if (hasCustomSearchFilter) { if (searchable == null) { searchable = Searchable.newSearchable(); } for (String name : searcheableMap.keySet()) { String[] mapValues = filterSearchValues(searcheableMap.get(name)); if (mapValues.length == 1) { if (name.endsWith("in")) { searchable.addSearchParam(name, StringUtils.split(mapValues[0], ",; ")); } else { searchable.addSearchParam(name, mapValues[0]); } } else { searchable.addSearchParam(name, mapValues); } } } Pageable pageable = (Pageable) pageableMethodArgumentResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); if (searchDefaults == null) { searchable.setPage(pageable); } if (searchDefaults != null && searchDefaults.needPage()) { searchable.setPage(pageable); } if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) { searchable.addSort(pageable.getSort()); } return searchable; }  }
SearchableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { String searchPrefix = getSearchPrefix(parameter); Map<String, String[]> searcheableMap = getPrefixParameterMap(searchPrefix, webRequest, true); boolean hasCustomSearchFilter = searcheableMap.size() > 0; SearchableDefaults searchDefaults = getSearchableDefaults(parameter); boolean needMergeDefault = searchDefaults != null && searchDefaults.merge(); Searchable searchable = null; if (needMergeDefault || !hasCustomSearchFilter) { searchable = getDefaultFromAnnotation(searchDefaults); } if (hasCustomSearchFilter) { if (searchable == null) { searchable = Searchable.newSearchable(); } for (String name : searcheableMap.keySet()) { String[] mapValues = filterSearchValues(searcheableMap.get(name)); if (mapValues.length == 1) { if (name.endsWith("in")) { searchable.addSearchParam(name, StringUtils.split(mapValues[0], ",; ")); } else { searchable.addSearchParam(name, mapValues[0]); } } else { searchable.addSearchParam(name, mapValues); } } } Pageable pageable = (Pageable) pageableMethodArgumentResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); if (searchDefaults == null) { searchable.setPage(pageable); } if (searchDefaults != null && searchDefaults.needPage()) { searchable.setPage(pageable); } if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) { searchable.addSort(pageable.getSort()); } return searchable; }  void setPrefix(String prefix); void setPageableMethodArgumentResolver(PageableMethodArgumentResolver pageableMethodArgumentResolver); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory); }
SearchableMethodArgumentResolver extends BaseMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { String searchPrefix = getSearchPrefix(parameter); Map<String, String[]> searcheableMap = getPrefixParameterMap(searchPrefix, webRequest, true); boolean hasCustomSearchFilter = searcheableMap.size() > 0; SearchableDefaults searchDefaults = getSearchableDefaults(parameter); boolean needMergeDefault = searchDefaults != null && searchDefaults.merge(); Searchable searchable = null; if (needMergeDefault || !hasCustomSearchFilter) { searchable = getDefaultFromAnnotation(searchDefaults); } if (hasCustomSearchFilter) { if (searchable == null) { searchable = Searchable.newSearchable(); } for (String name : searcheableMap.keySet()) { String[] mapValues = filterSearchValues(searcheableMap.get(name)); if (mapValues.length == 1) { if (name.endsWith("in")) { searchable.addSearchParam(name, StringUtils.split(mapValues[0], ",; ")); } else { searchable.addSearchParam(name, mapValues[0]); } } else { searchable.addSearchParam(name, mapValues); } } } Pageable pageable = (Pageable) pageableMethodArgumentResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); if (searchDefaults == null) { searchable.setPage(pageable); } if (searchDefaults != null && searchDefaults.needPage()) { searchable.setPage(pageable); } if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) { searchable.addSort(pageable.getSort()); } return searchable; }  void setPrefix(String prefix); void setPageableMethodArgumentResolver(PageableMethodArgumentResolver pageableMethodArgumentResolver); @Override boolean supportsParameter(MethodParameter parameter); @Override Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory);  }