Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class RequestPartMethodArgumentResolver

extends AbstractMessageConverterMethodArgumentResolver
Class Inheritance
Imports
java.io.IOException, .InputStream, java.util.List, jakarta.servlet.http.HttpServletRequest, org.springframework.core.MethodParameter, .ResolvableType, org.springframework.http.HttpInputMessage, org.springframework.http.converter.HttpMessageConverter, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.validation.BindingResult, org.springframework.web.bind.MethodArgumentNotValidException, .WebDataBinder, org.springframework.web.bind.annotation.RequestBody, .RequestParam, .RequestPart, org.springframework.web.bind.support.WebDataBinderFactory, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.method.support.ModelAndViewContainer, org.springframework.web.multipart.MultipartException, .MultipartFile, .MultipartResolver, org.springframework.web.multipart.support.MissingServletRequestPartException, .MultipartResolutionDelegate, .RequestPartServletServerHttpRequest

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 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 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver is configured.

Authors
Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
Since
3.1

Field Summary

Inherited from org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver:
loggermessageConverters

Constructor Summary

AccessConstructor and Description
public
RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters)

Basic constructor with converters only.

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

Constructor with converters and RequestBodyAdvice and ResponseBodyAdvice.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
closeStreamIfNecessary(InputStream body)

Overrides org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.closeStreamIfNecessary.

Allow for closing the body stream if necessary, e.g. for part streams in a multipart request.

private String
getPartName(MethodParameter methodParam, RequestPart requestPart)

public Object
resolveArgument(MethodParameter
the method parameter to resolve. This parameter must have previously been passed to supportsParameter which must have returned true.
parameter
,
ModelAndViewContainer
the ModelAndViewContainer for the current request
mavContainer
,
NativeWebRequest
the current request
request
,
WebDataBinderFactory
a factory for creating WebDataBinder instances
binderFactory
)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Resolves a method parameter into an argument value from a given request.

public boolean
supportsParameter(MethodParameter
the method parameter to check
parameter
)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

Whether the given method parameter is supported as multipart.

Inherited from org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver:
adaptArgumentIfNecessarycreateInputMessagegetAdvicegetSupportedMediaTypesisBindExceptionRequiredreadWithMessageConvertersreadWithMessageConvertersvalidateIfApplicable

Constructor Detail

RequestPartMethodArgumentResolverback to summary
public RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters)

Basic constructor with converters only.

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

Constructor with converters and RequestBodyAdvice and ResponseBodyAdvice.

Method Detail

closeStreamIfNecessaryback to summary
pack-priv void closeStreamIfNecessary(InputStream body)

Overrides org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.closeStreamIfNecessary.

Doc from org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.closeStreamIfNecessary.

Allow for closing the body stream if necessary, e.g. for part streams in a multipart request.

Annotations
@Override
getPartNameback to summary
private String getPartName(MethodParameter methodParam, RequestPart requestPart)
resolveArgumentback to summary
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.resolveArgument.

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:MethodParameter

the method parameter to resolve. This parameter must have previously been passed to supportsParameter which must have returned true.

mavContainer:ModelAndViewContainer

the ModelAndViewContainer for the current request

request:NativeWebRequest

the current request

binderFactory:WebDataBinderFactory

a factory for creating WebDataBinder instances

Returns:Object

the resolved argument value, or null if not resolvable

Annotations
@Override
@Nullable
Exceptions
Exception:
in case of errors with the preparation of argument values
supportsParameterback to summary
public boolean supportsParameter(MethodParameter parameter)

Implements org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

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 jakarta.servlet.http.Part unless annotated with @RequestParam
Parameters
parameter:MethodParameter

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

the method parameter to check

Returns:boolean

Doc from org.springframework.web.method.support.HandlerMethodArgumentResolver.supportsParameter.

true if this resolver supports the supplied parameter; false otherwise

Annotations
@Override