HandlerMethodArgumentResolver的抽象實現AbstractNamedValueMethodArgumentResolver下的子类 部分1
RequestParamMapMethodArgumentResolver // 存在@RequestParam注解并且该注解中name属性无值 public boolean supportsParameter(MethodParameter parameter) { RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); return (requestParam != null && Map.class.isAssignableFrom(parameter.getParameterType()) && !StringUtils.hasText(requestParam.name())); } 可以使用以下6中方式接收参数 MultiValueMap<String, MultipartFile> 相当于==》 Map<String, List<MultipartFile>> LinkedMultiValueMap<String, Part> 相当于==> LinkedHashMap<String, List<Part>> MultiValueMap<String, String> 相当于==> Map<String, List<String>> Map<String, MultipartFile> LinkedHashMap<String, Part> Map<String, String> PathVariableMapMethodArgumentResolver public boolean supportsParameter(MethodParameter parameter) { PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); return (ann != null && Map.class.isAssignableFrom(parameter.getParameterType()) && !StringUtils.hasText(ann.value())); } 如下方式使用: @PathVariable LinkedHashMap<String, String> paths MatrixVariableMapMethodArgumentResolver // 存在@MatrixVariable注解并且该注解中name属性无值 public boolean supportsParameter(MethodParameter parameter) { MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class); return (matrixVariable != null && Map.class.isAssignableFrom(parameter.getParameterType()) && !StringUtils.hasText(matrixVariable.name())); } // 以下使用方式 MultiValueMap<String, String> RequestHeaderMapMethodArgumentResolver // 存在@RequestHeader 并且 参数类型为Map.class.isAssignableFrom public boolean supportsParameter(MethodParameter parameter) { return (parameter.hasParameterAnnotation(RequestHeader.class) && Map.class.isAssignableFrom(parameter.getParameterType())); } 以下方式使用,使用如下参数类型: MultiValueMap<String, String> HttpHeaders Map<String, String> RequestPartMethodArgumentResolver ServletModelAttributeMethodProcessor RequestResponseBodyMethodProcessor
Annotation-based argument resolution 部分2
原文:https://www.cnblogs.com/hfultrastrong/p/12064573.html