类 AbstractMessageConverterMethodArgumentResolver
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- 所有已实现的接口:
HandlerMethodArgumentResolver
public abstract class AbstractMessageConverterMethodArgumentResolver extends Object implements HandlerMethodArgumentResolver
A base class for resolving method argument values by reading from the body of a request withHttpMessageConverters
.- 从以下版本开始:
- 3.1
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
字段概要
字段 修饰符和类型 字段 说明 protected List<MediaType>
allSupportedMediaTypes
protected Log
logger
protected List<HttpMessageConverter<?>>
messageConverters
构造器概要
构造器 构造器 说明 AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)
Constructor with converters andRequest~
andResponseBodyAdvice
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Object
adaptArgumentIfNecessary(Object arg, MethodParameter parameter)
Adapt the given argument against the method parameter, if necessary.protected ServletServerHttpRequest
createInputMessage(NativeWebRequest webRequest)
Create a newHttpInputMessage
from the givenNativeWebRequest
.protected boolean
isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter)
Whether to raise a fatal bind exception on validation errors.protected <T> Object
readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType)
Create the method argument value of the expected parameter type by reading from the given HttpInputMessage.protected <T> Object
readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType)
Create the method argument value of the expected parameter type by reading from the given request.protected void
validateIfApplicable(WebDataBinder binder, MethodParameter parameter)
Validate the binding target if applicable.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.web.method.support.HandlerMethodArgumentResolver
resolveArgument, supportsParameter
字段详细资料
messageConverters
protected final List<HttpMessageConverter<?>> messageConverters
allSupportedMediaTypes
protected final List<MediaType> allSupportedMediaTypes
构造器详细资料
AbstractMessageConverterMethodArgumentResolver
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.
AbstractMessageConverterMethodArgumentResolver
public AbstractMessageConverterMethodArgumentResolver(List<HttpMessageConverter<?>> converters, @Nullable List<Object> requestResponseBodyAdvice)
Constructor with converters andRequest~
andResponseBodyAdvice
.- 从以下版本开始:
- 4.2
方法详细资料
readWithMessageConverters
@Nullable protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException
Create the method argument value of the expected parameter type by reading from the given request.- 类型参数:
T
- the expected type of the argument value to be created- 参数:
webRequest
- the current requestparameter
- the method parameter descriptor (may benull
)paramType
- the type of the argument value to be created- 返回:
- the created method argument value
- 抛出:
IOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundHttpMessageNotReadableException
readWithMessageConverters
@Nullable protected <T> Object readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException
Create the method argument value of the expected parameter type by reading from the given HttpInputMessage.- 类型参数:
T
- the expected type of the argument value to be created- 参数:
inputMessage
- the HTTP input message representing the current requestparameter
- the method parameter descriptortargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.- 返回:
- the created method argument value
- 抛出:
IOException
- if the reading from the request failsHttpMediaTypeNotSupportedException
- if no suitable message converter is foundHttpMessageNotReadableException
createInputMessage
protected ServletServerHttpRequest createInputMessage(NativeWebRequest webRequest)
Create a newHttpInputMessage
from the givenNativeWebRequest
.- 参数:
webRequest
- the web request to create an input message from- 返回:
- the input message
validateIfApplicable
protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter)
Validate the binding target if applicable.The default implementation checks for
@javax.validation.Valid
, Spring'sValidated
, and custom annotations whose name starts with "Valid".- 参数:
binder
- the DataBinder to be usedparameter
- the method parameter descriptor- 从以下版本开始:
- 4.1.5
- 另请参阅:
isBindExceptionRequired(org.springframework.web.bind.WebDataBinder, org.springframework.core.MethodParameter)
isBindExceptionRequired
protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter)
Whether to raise a fatal bind exception on validation errors.- 参数:
binder
- the data binder used to perform data bindingparameter
- the method parameter descriptor- 返回:
true
if the next method argument is not of typeErrors
- 从以下版本开始:
- 4.1.5
adaptArgumentIfNecessary
@Nullable protected Object adaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter)
Adapt the given argument against the method parameter, if necessary.- 参数:
arg
- the resolved argumentparameter
- the method parameter descriptor- 返回:
- the adapted argument, or the original resolved argument as-is
- 从以下版本开始:
- 4.3.5