org.springframework.web.servlet.mvc.method.annotation

## Class RequestPartMethodArgumentResolver

- java.lang.Object
- - org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
  - - org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver

- All Implemented Interfaces:
    HandlerMethodArgumentResolver

      public class RequestPartMethodArgumentResolver
      extends AbstractMessageConverterMethodArgumentResolver

  Resolves the following method arguments:
  - Annotated with @`RequestPart`
  - Of type `MultipartFile` in conjunction with Spring's `MultipartResolver` abstraction
  - Of type `javax.servlet.http.Part` in conjunction with Servlet 3.0 multipart requests

  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 with `@RequestPart` or the name of the part is not specified, the request part's name is derived from the name of the method argument.

  Automatic validation may be applied if the argument is annotated with any annotations that trigger validation. In case of validation failure, a `MethodArgumentNotValidException` is raised and a 400 response status code returned if the `DefaultHandlerExceptionResolver` is configured.

  Since:
    3.1
  Author:
    Rossen Stoyanchev, Brian Clozel, Juergen Hoeller

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver

      `logger, messageConverters`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters)` Basic constructor with converters only.
    `RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters, List<Object> requestResponseBodyAdvice)` Constructor with converters and `RequestBodyAdvice` and `ResponseBodyAdvice`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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)` Whether the given method parameter is supported as multipart.

    - ### Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver

      `adaptArgumentIfNecessary, createInputMessage, getSupportedMediaTypes, isBindExceptionRequired, readWithMessageConverters, readWithMessageConverters, validateIfApplicable`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RequestPartMethodArgumentResolver

          public RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters)

      Basic constructor with converters only.

    - #### RequestPartMethodArgumentResolver

          public RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters,
                                                   List<Object> requestResponseBodyAdvice)

      Constructor with converters and `RequestBodyAdvice` and `ResponseBodyAdvice`.

  - ### Method Detail

    - #### supportsParameter

          public boolean supportsParameter(MethodParameter parameter)

      Whether the given method parameter is supported as multipart. Supports the following method parameters:
      - annotated with `@RequestPart`
      - of type `MultipartFile` unless annotated with `@RequestParam`
      - of type `javax.servlet.http.Part` unless annotated with `@RequestParam`
      Parameters:
        `parameter` - the method parameter to check
      Returns:
        `true` if this resolver supports the supplied parameter; `false` otherwise

    - #### resolveArgument

          @Nullable
          public Object resolveArgument(MethodParameter parameter,
                                                  @Nullable
                                                  ModelAndViewContainer mavContainer,
                                                  NativeWebRequest request,
                                                  @Nullable
                                                  WebDataBinderFactory binderFactory)
                                           throws 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.
      Parameters:
        `parameter` - the method parameter to resolve. This parameter must have previously been passed to `HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)` which must have returned `true`.
        `mavContainer` - the ModelAndViewContainer for the current request
        `request` - the current request
        `binderFactory` - a factory for creating `WebDataBinder` instances
      Returns:
        the resolved argument value, or `null` if not resolvable
      Throws:
        `Exception` - in case of errors with the preparation of argument values