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

  

Annotation-based argument resolution 部分2的更多相关文章

  1. An annotation based command line parser

    Java命令行选项解析之Commons-CLI & Args4J & JCommander http://rensanning.iteye.com/blog/2161201 JComm ...

  2. [转载]Spring Annotation Based Configuration

    Annotation injection is performed before XML injection, thus the latter configuration will override ...

  3. spring Annotation based configuration

    spring 注解相关 https://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch04s11.html

  4. 译:Spring框架参考文档之IoC容器(未完成)

    6. IoC容器 6.1 Spring IoC容器和bean介绍 这一章节介绍了Spring框架的控制反转(IoC)实现的原理.IoC也被称作依赖注入(DI).It is a process wher ...

  5. springmvc 请求参数解析细节

    springmvc 的请求流程,相信大家已经很熟悉了,不熟悉的同学可以参考下资料! 有了整体流程的概念,是否对其中的实现细节就很清楚呢?我觉得不一定,比如:单是参数解析这块,就是个大学问呢? 首先,我 ...

  6. 摘抄JPA官方文档原文 防呆

    Spring Data JPA - Reference Documentation Oliver GierkeThomas DarimontChristoph StroblMark PaluchVer ...

  7. SpringMVC深度探险(二) —— SpringMVC概览

    对于任何事物的研究,总是由表及里.由浅入深地进行.在本系列的第二篇文章中,我们将通过不同的观察视角,对SpringMVC做一些概要性的分析,帮助大家了解SpringMVC的基本构成要素.SpringM ...

  8. Spring MVC之源码速读之RequestMappingHandlerAdapter

    spring-webmvc-4.3.19.RELEASE 下面来看DispatcherServlet中的执行: /** * Exposes the DispatcherServlet-specific ...

  9. Spring框架文档与API(4.3.6版本)

    http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/ Table of Contents I ...

随机推荐

  1. .Net core 在类库中获取配置文件Appsettings中的值

    大多数情况,我们开发的程序中都含有很多个类库和文件夹,有时候,我们会遇到程序中的类库需要获取配置文件的信息的情况. 像dapper 中需要使用连接字符串的时候,那么我们一直从主程序中传值这是个不好的方 ...

  2. 【转载】自定义View学习笔记之详解onMeasure

    网上对自定义View总结的文章都很多,但是自己还是写一篇,好记性不如多敲字! 其实自定义View就是三大流程,onMeasure.onLayout.onDraw.看名字就知道,onMeasure是用来 ...

  3. jQuery和使用oninput事件

  4. 第七篇 -- XmlReader 和 XmlWriter

    XmlReader用于读取Xml文件,XmlWriter用于将数据写到Xml文件.其实,在印象当中,XML很多的操作类都支持直接Save.Read也支持接受XmlReader与XmlWriter类的示 ...

  5. nuxt 中使用 koa-session

    官方 github 网址:https://github.com/koajs/session 自己做的demo:https://github.com/cag2050/nuxt_session_demo ...

  6. Bootstrap 学习笔记1

    <img src="..." class="img-responsive" alt="响应式图像"> 通过添加 img-resp ...

  7. class struct Equals

    { class clsA { private int _i; public int I { set { _i = value; } get { return _i; } } } struct strc ...

  8. async await 总结

    1.async await成对出现,await再async定义的函数内 2.async定义的是函数 3.async 返回一个Promise 4.async 函数中 return 的结果将作为回调的参数 ...

  9. 排序算法-选择排序(Java)

    package com.rao.linkList; import java.util.Arrays; /** * @author Srao * @className SelectSort * @dat ...

  10. (0)开始 Raspberry Pi 项目前需要知道的 10 件事

    https://www.digikey.cn/zh/articles/techzone/2017/feb/10-things-to-know-before-starting-a-raspberry-p ...