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);
}
//needPage=true 分页及排序
if (searchDefaults != null && searchDefaults.needPage()) {
searchable.setPage(pageable);
}
//needPage=false needSort=true 不要分页,但排序
if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) {
searchable.addSort(pageable.getSort());
}
return searchable;
}