类 RequestPartMethodArgumentResolver
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver
- 所有已实现的接口:
HandlerMethodArgumentResolver
public class RequestPartMethodArgumentResolver extends AbstractMessageConverterMethodArgumentResolver
Resolves the following method arguments:- Annotated with @
RequestPart
- Of type
MultipartFile
in conjunction with Spring'sMultipartResolver
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 anHttpMessageConverter
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, aMethodArgumentNotValidException
is raised and a 400 response status code returned ifDefaultHandlerExceptionResolver
is configured.- 从以下版本开始:
- 3.1
- 作者:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
allSupportedMediaTypes, logger, messageConverters
构造器概要
构造器 构造器 说明 RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters)
Basic constructor with converters only.RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters, List<Object> requestResponseBodyAdvice)
Constructor with converters andRequest~
andResponseBodyAdvice
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 a multi-part supported.从类继承的方法 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
adaptArgumentIfNecessary, createInputMessage, getAdvice, isBindExceptionRequired, readWithMessageConverters, readWithMessageConverters, validateIfApplicable
构造器详细资料
RequestPartMethodArgumentResolver
public RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters)
Basic constructor with converters only.
RequestPartMethodArgumentResolver
public RequestPartMethodArgumentResolver(List<HttpMessageConverter<?>> messageConverters, List<Object> requestResponseBodyAdvice)
Constructor with converters andRequest~
andResponseBodyAdvice
.
方法详细资料
supportsParameter
public boolean supportsParameter(MethodParameter parameter)
Whether the given method parameter is a multi-part supported. Supports the following:- annotated with
@RequestPart
- of type
MultipartFile
unless annotated with@RequestParam
- of type
javax.servlet.http.Part
unless annotated with@RequestParam
- 参数:
parameter
- the method parameter to check- 返回:
true
if this resolver supports the supplied parameter;false
otherwise
- annotated with
resolveArgument
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception
从接口复制的说明:HandlerMethodArgumentResolver
Resolves a method parameter into an argument value from a given request. AModelAndViewContainer
provides access to the model for the request. AWebDataBinderFactory
provides a way to create aWebDataBinder
instance when needed for data binding and type conversion purposes.- 参数:
parameter
- the method parameter to resolve. This parameter must have previously been passed toHandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
which must have returnedtrue
.mavContainer
- the ModelAndViewContainer for the current requestrequest
- the current requestbinderFactory
- a factory for creatingWebDataBinder
instances- 返回:
- the resolved argument value, or
null
- 抛出:
Exception
- in case of errors with the preparation of argument values