Skip to content

Commit de3734a

Browse files
committed
Polishing
1 parent d518ac6 commit de3734a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,16 +38,19 @@
3838
* Abstract base class for resolving method arguments from a named value.
3939
* Request parameters, request headers, and path variables are examples of named
4040
* values. Each may have a name, a required flag, and a default value.
41+
*
4142
* <p>Subclasses define how to do the following:
4243
* <ul>
4344
* <li>Obtain named value information for a method parameter
4445
* <li>Resolve names into argument values
4546
* <li>Handle missing argument values when argument values are required
4647
* <li>Optionally handle a resolved value
4748
* </ul>
49+
*
4850
* <p>A default value string can contain ${...} placeholders and Spring Expression
4951
* Language #{...} expressions. For this to work a
5052
* {@link ConfigurableBeanFactory} must be supplied to the class constructor.
53+
*
5154
* <p>A {@link WebDataBinder} is created to apply type conversion to the resolved
5255
* argument value if it doesn't match the method parameter type.
5356
*
@@ -61,7 +64,8 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
6164

6265
private final BeanExpressionContext expressionContext;
6366

64-
private Map<MethodParameter, NamedValueInfo> namedValueInfoCache = new ConcurrentHashMap<MethodParameter, NamedValueInfo>(256);
67+
private final Map<MethodParameter, NamedValueInfo> namedValueInfoCache =
68+
new ConcurrentHashMap<MethodParameter, NamedValueInfo>(256);
6569

6670

6771
public AbstractNamedValueMethodArgumentResolver() {
@@ -76,7 +80,8 @@ public AbstractNamedValueMethodArgumentResolver() {
7680
*/
7781
public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) {
7882
this.configurableBeanFactory = beanFactory;
79-
this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null);
83+
this.expressionContext =
84+
(beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null);
8085
}
8186

8287

@@ -151,7 +156,8 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
151156
if (info.name.length() == 0) {
152157
name = parameter.getParameterName();
153158
if (name == null) {
154-
throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() +
159+
throw new IllegalArgumentException(
160+
"Name for argument type [" + parameter.getParameterType().getName() +
155161
"] not available, and parameter name information not found in class file either.");
156162
}
157163
}
@@ -160,18 +166,19 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
160166
}
161167

162168
/**
163-
* Resolves the given parameter type and value name into an argument value.
169+
* Resolve the given parameter type and value name into an argument value.
164170
* @param name the name of the value being resolved
165171
* @param parameter the method parameter to resolve to an argument value
166172
* @param request the current request
167-
* @return the resolved argument. May be {@code null}
173+
* @return the resolved argument (may be {@code null})
168174
* @throws Exception in case of errors
169175
*/
170176
protected abstract Object resolveName(String name, MethodParameter parameter, NativeWebRequest request)
171177
throws Exception;
172178

173179
/**
174-
* Resolves the given default value into an argument value.
180+
* Resolve the given annotation-specified value,
181+
* potentially containing placeholders and expressions.
175182
*/
176183
private Object resolveDefaultValue(String defaultValue) {
177184
if (this.configurableBeanFactory == null) {
@@ -215,7 +222,7 @@ else if (paramType.isPrimitive()) {
215222
* @param arg the resolved argument value
216223
* @param name the argument name
217224
* @param parameter the argument parameter type
218-
* @param mavContainer the {@link ModelAndViewContainer}, which may be {@code null}
225+
* @param mavContainer the {@link ModelAndViewContainer} (may be {@code null})
219226
* @param webRequest the current request
220227
*/
221228
protected void handleResolvedValue(Object arg, String name, MethodParameter parameter,

spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
8585
/**
8686
* @param useDefaultResolution in default resolution mode a method argument
8787
* that is a simple type, as defined in {@link BeanUtils#isSimpleProperty},
88-
* is treated as a request parameter even if it it isn't annotated, the
88+
* is treated as a request parameter even if it isn't annotated, the
8989
* request parameter name is derived from the method parameter name.
9090
*/
9191
public RequestParamMethodArgumentResolver(boolean useDefaultResolution) {
@@ -98,7 +98,7 @@ public RequestParamMethodArgumentResolver(boolean useDefaultResolution) {
9898
* values are not expected to contain expressions
9999
* @param useDefaultResolution in default resolution mode a method argument
100100
* that is a simple type, as defined in {@link BeanUtils#isSimpleProperty},
101-
* is treated as a request parameter even if it it isn't annotated, the
101+
* is treated as a request parameter even if it isn't annotated, the
102102
* request parameter name is derived from the method parameter name.
103103
*/
104104
public RequestParamMethodArgumentResolver(ConfigurableBeanFactory beanFactory, boolean useDefaultResolution) {

0 commit comments

Comments
 (0)