multipartFileList,
int i,
MultipartFile multipartFileNotAnnot,
- Part servlet30Part) {
+ Part servlet30Part,
+ @RequestParam MultipartFile requestParamAnnot) {
}
}
diff --git a/org.springframework.web.servlet/src/test/resources/org/springframework/web/servlet/mvc/method/annotation/support/logo.jpg b/org.springframework.web.servlet/src/test/resources/org/springframework/web/servlet/mvc/method/annotation/support/logo.jpg
new file mode 100644
index 00000000000..8a70e6af172
Binary files /dev/null and b/org.springframework.web.servlet/src/test/resources/org/springframework/web/servlet/mvc/method/annotation/support/logo.jpg differ
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolver.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolver.java
index 110ef0fac18..24f3f90dd97 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolver.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolver.java
@@ -33,6 +33,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ValueConstants;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;
@@ -85,35 +86,38 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
/**
* Supports the following:
*
- * - @RequestParam method arguments. This excludes the case where a parameter is of type
- * {@link Map} and the annotation does not specify a request parameter name. See
- * {@link RequestParamMapMethodArgumentResolver} instead for such parameters.
- *
- Arguments of type {@link MultipartFile} even if not annotated.
- *
- Arguments of type {@code javax.servlet.http.Part} even if not annotated.
+ *
- @RequestParam-annotated method arguments.
+ * This excludes {@link Map} parameters where the annotation does not specify a name value.
+ * See {@link RequestParamMapMethodArgumentResolver} instead for such parameters.
+ *
- Arguments of type {@link MultipartFile} unless annotated with {@link RequestPart}.
+ *
- Arguments of type {@code javax.servlet.http.Part} unless annotated with {@link RequestPart}.
+ *
- In default resolution mode, simple type arguments even if not with @RequestParam.
*
- *
- * In default resolution mode, simple type arguments not annotated with @RequestParam are also supported.
*/
public boolean supportsParameter(MethodParameter parameter) {
Class> paramType = parameter.getParameterType();
- RequestParam requestParamAnnot = parameter.getParameterAnnotation(RequestParam.class);
- if (requestParamAnnot != null) {
+ if (parameter.hasParameterAnnotation(RequestParam.class)) {
if (Map.class.isAssignableFrom(paramType)) {
- return StringUtils.hasText(requestParamAnnot.value());
+ String paramName = parameter.getParameterAnnotation(RequestParam.class).value();
+ return StringUtils.hasText(paramName);
+ }
+ else {
+ return true;
}
- return true;
- }
- else if (MultipartFile.class.equals(paramType)) {
- return true;
- }
- else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
- return true;
- }
- else if (this.useDefaultResolution) {
- return BeanUtils.isSimpleProperty(paramType);
}
else {
- return false;
+ if (parameter.hasParameterAnnotation(RequestPart.class)) {
+ return false;
+ }
+ else if (MultipartFile.class.equals(paramType) || "javax.servlet.http.Part".equals(paramType.getName())) {
+ return true;
+ }
+ else if (this.useDefaultResolution) {
+ return BeanUtils.isSimpleProperty(paramType);
+ }
+ else {
+ return false;
+ }
}
}
diff --git a/org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolverTests.java b/org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolverTests.java
index 3e8364ff88f..10884503207 100644
--- a/org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolverTests.java
+++ b/org.springframework.web/src/test/java/org/springframework/web/method/annotation/support/RequestParamMethodArgumentResolverTests.java
@@ -41,6 +41,7 @@ import org.springframework.mock.web.MockMultipartHttpServletRequest;
import org.springframework.mock.web.MockPart;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.multipart.MultipartFile;
@@ -64,6 +65,7 @@ public class RequestParamMethodArgumentResolverTests {
private MethodParameter paramMultipartFileNotAnnot;
private MethodParameter paramMultipartFileList;
private MethodParameter paramServlet30Part;
+ private MethodParameter paramRequestPartAnnot;
private NativeWebRequest webRequest;
@@ -76,7 +78,7 @@ public class RequestParamMethodArgumentResolverTests {
ParameterNameDiscoverer paramNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
Method method = getClass().getMethod("params", String.class, String[].class, Map.class, MultipartFile.class,
- Map.class, String.class, MultipartFile.class, List.class, Part.class);
+ Map.class, String.class, MultipartFile.class, List.class, Part.class, MultipartFile.class);
paramNamedDefaultValueString = new MethodParameter(method, 0);
paramNamedStringArray = new MethodParameter(method, 1);
@@ -91,6 +93,7 @@ public class RequestParamMethodArgumentResolverTests {
paramMultipartFileList.initParameterNameDiscovery(paramNameDiscoverer);
paramServlet30Part = new MethodParameter(method, 8);
paramServlet30Part.initParameterNameDiscovery(paramNameDiscoverer);
+ paramRequestPartAnnot = new MethodParameter(method, 9);
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
@@ -110,6 +113,7 @@ public class RequestParamMethodArgumentResolverTests {
resolver = new RequestParamMethodArgumentResolver(null, false);
assertFalse(resolver.supportsParameter(paramStringNotAnnot));
+ assertFalse(resolver.supportsParameter(paramRequestPartAnnot));
}
@Test
@@ -225,7 +229,8 @@ public class RequestParamMethodArgumentResolverTests {
String stringNotAnnot,
MultipartFile multipartFileNotAnnot,
List multipartFileList,
- Part servlet30Part) {
+ Part servlet30Part,
+ @RequestPart MultipartFile requestPartAnnot) {
}
}