Class RequestPartMethodArgumentResolver
- All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver
- Annotated with @
RequestPart
- Of type
MultipartFile
in conjunction with Spring'sMultipartResolver
abstraction - Of type
jakarta.servlet.http.Part
in conjunction with Servlet 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
ConstructorDescriptionRequestPartMethodArgumentResolver
(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters) Basic constructor with converters only.RequestPartMethodArgumentResolver
(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters, List<Object> requestResponseBodyAdvice) Constructor with converters andRequestBodyAdvice
andResponseBodyAdvice
. -
Method Summary
Modifier and TypeMethodDescriptionresolveArgument
(org.springframework.core.MethodParameter parameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest request, org.springframework.web.bind.support.WebDataBinderFactory binderFactory) boolean
supportsParameter
(org.springframework.core.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
-
Constructor Details
-
RequestPartMethodArgumentResolver
public RequestPartMethodArgumentResolver(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters) Basic constructor with converters only. -
RequestPartMethodArgumentResolver
public RequestPartMethodArgumentResolver(List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters, List<Object> requestResponseBodyAdvice) Constructor with converters andRequestBodyAdvice
andResponseBodyAdvice
.
-
-
Method Details
-
supportsParameter
public boolean supportsParameter(org.springframework.core.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
jakarta.servlet.http.Part
unless annotated with@RequestParam
- annotated with
-
resolveArgument
@Nullable public Object resolveArgument(org.springframework.core.MethodParameter parameter, @Nullable org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest request, @Nullable org.springframework.web.bind.support.WebDataBinderFactory binderFactory) throws Exception - Throws:
Exception
-