zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    Alpha冲刺Day5
    Alpha冲刺Day4
    Alpha冲刺Day3
    团队作业——随堂小测
    Alpha冲刺Day2
    Alpha冲刺Day1
    团队项目需求分析
    结对项目第二次作业
    Linux中exec命令相关
    .lib和.dll文件
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/12064573.html
Copyright © 2011-2022 走看看