SPR-8483 Add integration test for accessing multipart request parts with @RequestPart

This commit is contained in:
Rossen Stoyanchev
2011-07-21 16:24:33 +00:00
parent 1b26b4744f
commit 3363d05879
10 changed files with 344 additions and 35 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.validation.Errors;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
@@ -79,23 +80,28 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
/**
* Supports the following:
* <ul>
* <li>@RequestPart method arguments.
* <li>Arguments of type {@link MultipartFile} even if not annotated.
* <li>Arguments of type {@code javax.servlet.http.Part} even if not annotated.
* <li>@RequestPart-annotated method arguments.
* <li>Arguments of type {@link MultipartFile} unless annotated with {@link RequestParam}.
* <li>Arguments of type {@code javax.servlet.http.Part} unless annotated with {@link RequestParam}.
* </ul>
*/
public boolean supportsParameter(MethodParameter parameter) {
if (parameter.hasParameterAnnotation(RequestPart.class)) {
return true;
}
else if (MultipartFile.class.equals(parameter.getParameterType())) {
return true;
}
else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
return true;
}
else {
return false;
if (parameter.hasParameterAnnotation(RequestParam.class)){
return false;
}
else if (MultipartFile.class.equals(parameter.getParameterType())) {
return true;
}
else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
return true;
}
else {
return false;
}
}
}