SpringMvc参数解析器

SpringMvc 默认的参数解析器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();

// 基于注解的参数解析器
resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); // @RequestParam 注解, 非Map参数
resolvers.add(new RequestParamMapMethodArgumentResolver()); // @RequestParam 注解, 并且是Map的参数

resolvers.add(new PathVariableMethodArgumentResolver()); // @PathVariable 注解, 非Map参数
resolvers.add(new PathVariableMapMethodArgumentResolver()); // @PathVariable 注解, Map参数

resolvers.add(new MatrixVariableMethodArgumentResolver()); // @MatrixVariable 注解, 非Map参数
resolvers.add(new MatrixVariableMapMethodArgumentResolver()); // @MatrixVariable 注解, Map参数

resolvers.add(new ServletModelAttributeMethodProcessor(false)); // @ModelAttribute 注解的参数

resolvers.add(new RequestResponseBodyMethodProcessor(getMessageConverters(), this.requestResponseBodyAdvice)); // @RequestBody

resolvers.add(new RequestPartMethodArgumentResolver(getMessageConverters(), this.requestResponseBodyAdvice)); // @RequestPart

resolvers.add(new RequestHeaderMethodArgumentResolver(getBeanFactory())); // @RequestHeader 非Map
resolvers.add(new RequestHeaderMapMethodArgumentResolver()); // @RequestHeader, Map参数

resolvers.add(new ServletCookieValueMethodArgumentResolver(getBeanFactory())); // @CookieValue

resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory())); // @Value

resolvers.add(new SessionAttributeMethodArgumentResolver()); // @SessionAttribute

resolvers.add(new RequestAttributeMethodArgumentResolver()); // @RequestAttribute

// 基于类型的参数解析器
resolvers.add(new ServletRequestMethodArgumentResolver()); // 填充参数列表中的 ServletRequest, InputStream, Reader, Locale 等参数
resolvers.add(new ServletResponseMethodArgumentResolver()); // 填充ServletResponse, OutputStream, Writer
resolvers.add(new HttpEntityMethodProcessor(getMessageConverters(), this.requestResponseBodyAdvice)); // RequestEntity类型
resolvers.add(new RedirectAttributesMethodArgumentResolver()); // RedirectAttributes类型
resolvers.add(new ModelMethodProcessor()); // mvc中的Model类型的参数
resolvers.add(new MapMethodProcessor()); // Map类型的参数
resolvers.add(new ErrorsMethodArgumentResolver()); // validation中的Errors类型的参数
resolvers.add(new SessionStatusMethodArgumentResolver()); // SessionStatus
resolvers.add(new UriComponentsBuilderMethodArgumentResolver()); // UriComponentsBuilder

// 自定义参数解析器
if (getCustomArgumentResolvers() != null) {
resolvers.addAll(getCustomArgumentResolvers());
}

// Catch-all
// 默认处理器, 上面那个必须有@RequestParam 注解, 这个可以不用该注解, 并且参数是简单参数 (a primitive, a String or other CharSequence, a Number, a Date, a URI, a URL, a Locale, a Class, or a corresponding array.)
resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true));

resolvers.add(new ServletModelAttributeMethodProcessor(true));

return resolvers;
}

0%