Annotation-based argument resolution 部分2
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 // 接收@RequestPart 并且不能包含 @ReqeusatParam // 并且满足 MultipartResolutionDelegate.isMultipartArgument 以下类型 也可以通过: MultipartFile List<MultipartFile> MultipartFile[] Part List<Part> Part[] @Override public boolean supportsParameter(MethodParameter parameter) { if (parameter.hasParameterAnnotation(RequestPart.class)) { return true; } else { if (parameter.hasParameterAnnotation(RequestParam.class)) { return false; } return MultipartResolutionDelegate.isMultipartArgument(parameter.nestedIfOptional()); } } 注解之后使用一下方式接收参数值: MultipartFile List<MultipartFile> MultipartFile[] Part List<Part> Part[] ServletModelAttributeMethodProcessor RequestResponseBodyMethodProcessor