Class RequestPartMethodArgumentResolver

  extended by
      extended by
All Implemented Interfaces:

public class RequestPartMethodArgumentResolver
extends AbstractMessageConverterMethodArgumentResolver

Resolves the following method arguments:

When a parameter is annotated with @RequestPart the content of the part is passed through an HttpMessageConverter to resolve the method argument with the 'Content-Type' of the request part in mind. This is analogous to what @RequestBody does to resolve an argument based on the content of a regular request.

When a parameter is not annotated or the name of the part is not specified, it is derived from the name of the method argument.

Automatic validation may be applied if the argument is annotated with @javax.validation.Valid. In case of validation failure, a MethodArgumentNotValidException is raised and a 400 response status code returned if DefaultHandlerExceptionResolver is configured.

Rossen Stoyanchev

Field Summary
Fields inherited from class
allSupportedMediaTypes, logger, messageConverters
Constructor Summary
RequestPartMethodArgumentResolver(java.util.List<HttpMessageConverter<?>> messageConverters)
Method Summary
private  java.lang.String getPartName(MethodParameter parameter)
private  boolean isMultipartFileCollection(MethodParameter parameter)
private  boolean isMultipartRequest(HttpServletRequest request)
protected  boolean isValidationApplicable(java.lang.Object argument, MethodParameter parameter)
          Whether to validate the given @RequestPart method argument.
 java.lang.Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request, WebDataBinderFactory binderFactory)
          Resolves a method parameter into an argument value from a given request.
 boolean supportsParameter(MethodParameter parameter)
          Supports the following: Annotated with @RequestPart Of type MultipartFile unless annotated with @RequestParam.
Methods inherited from class
createInputMessage, readWithMessageConverters, readWithMessageConverters
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public RequestPartMethodArgumentResolver(java.util.List<HttpMessageConverter<?>> messageConverters)
Method Detail


public boolean supportsParameter(MethodParameter parameter)
Supports the following:

parameter - the method parameter to check
true if this resolver supports the supplied parameter; false otherwise


public java.lang.Object resolveArgument(MethodParameter parameter,
                                        ModelAndViewContainer mavContainer,
                                        NativeWebRequest request,
                                        WebDataBinderFactory binderFactory)
                                 throws java.lang.Exception
Description copied from interface: HandlerMethodArgumentResolver
Resolves a method parameter into an argument value from a given request. A ModelAndViewContainer provides access to the model for the request. A WebDataBinderFactory provides a way to create a WebDataBinder instance when needed for data binding and type conversion purposes.

parameter - the method parameter to resolve. This parameter must have previously been passed to HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter) and it must have returned true
mavContainer - the ModelAndViewContainer for the current request
request - the current request
binderFactory - a factory for creating WebDataBinder instances
the resolved argument value, or null.
java.lang.Exception - in case of errors with the preparation of argument values


private boolean isMultipartRequest(HttpServletRequest request)


private java.lang.String getPartName(MethodParameter parameter)


private boolean isMultipartFileCollection(MethodParameter parameter)


protected boolean isValidationApplicable(java.lang.Object argument,
                                         MethodParameter parameter)
Whether to validate the given @RequestPart method argument. The default implementation looks for @javax.validation.Valid.

argument - the resolved argument value
parameter - the method argument