首页 > 其他 > 详细

Annotation-based argument resolution 部分2

时间:2019-12-19 01:39:21      阅读:131      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!