类 RequestResponseBodyMethodProcessor
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
- org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor
public class RequestResponseBodyMethodProcessor extends AbstractMessageConverterMethodProcessor
Resolves method arguments annotated with@RequestBody
and handles return values from methods annotated with@ResponseBody
by reading and writing to the body of the request or response with anHttpMessageConverter
.An
@RequestBody
method argument is also validated if it is annotated with@javax.validation.Valid
. In case of validation failure,MethodArgumentNotValidException
is raised and results in an HTTP 400 response status code ifDefaultHandlerExceptionResolver
is configured.- 从以下版本开始:
- 3.1
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
allSupportedMediaTypes, logger, messageConverters
构造器概要
构造器 构造器 说明 RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only.RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)
Complete constructor for resolving@RequestBody
method arguments.RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager)
Basic constructor with converters andContentNegotiationManager
.RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)
Complete constructor for resolving@RequestBody
and handling@ResponseBody
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected boolean
checkRequired(MethodParameter parameter)
void
handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
Handle the given return value by adding attributes to the model and setting a view or setting theModelAndViewContainer.setRequestHandled(boolean)
flag totrue
to indicate the response has been handled directly.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.Object
resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
Throws MethodArgumentNotValidException if validation fails.boolean
supportsParameter(MethodParameter parameter)
Whether the given method parameter is supported by this resolver.boolean
supportsReturnType(MethodParameter returnType)
Whether the given method return type is supported by this handler.从类继承的方法 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
createOutputMessage, getProducibleMediaTypes, getProducibleMediaTypes, getReturnValueType, writeWithMessageConverters, writeWithMessageConverters
从类继承的方法 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
adaptArgumentIfNecessary, createInputMessage, getAdvice, isBindExceptionRequired, readWithMessageConverters, validateIfApplicable
构造器详细资料
RequestResponseBodyMethodProcessor
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters)
Basic constructor with converters only. Suitable for resolving@RequestBody
. For handling@ResponseBody
consider also providing aContentNegotiationManager
.
RequestResponseBodyMethodProcessor
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager)
Basic constructor with converters andContentNegotiationManager
. Suitable for resolving@RequestBody
and handling@ResponseBody
withoutRequest~
orResponseBodyAdvice
.
RequestResponseBodyMethodProcessor
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice)
Complete constructor for resolving@RequestBody
method arguments. For handling@ResponseBody
consider also providing aContentNegotiationManager
.- 从以下版本开始:
- 4.2
RequestResponseBodyMethodProcessor
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)
Complete constructor for resolving@RequestBody
and handling@ResponseBody
.
方法详细资料
supportsParameter
public boolean supportsParameter(MethodParameter parameter)
从接口复制的说明:HandlerMethodArgumentResolver
Whether the given method parameter is supported by this resolver.- 参数:
parameter
- the method parameter to check- 返回:
true
if this resolver supports the supplied parameter;false
otherwise
supportsReturnType
public boolean supportsReturnType(MethodParameter returnType)
从接口复制的说明:HandlerMethodReturnValueHandler
Whether the given method return type is supported by this handler.- 参数:
returnType
- the method return type to check- 返回:
true
if this handler supports the supplied return type;false
otherwise
resolveArgument
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception
Throws MethodArgumentNotValidException if validation fails.- 参数:
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 requestwebRequest
- the current requestbinderFactory
- a factory for creatingWebDataBinder
instances- 返回:
- the resolved argument value, or
null
- 抛出:
HttpMessageNotReadableException
- ifRequestBody.required()
istrue
and there is no body content or if there is no suitable converter to read the content with.Exception
- in case of errors with the preparation of argument values
readWithMessageConverters
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.- 覆盖:
readWithMessageConverters
在类中AbstractMessageConverterMethodArgumentResolver
- 类型参数:
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
checkRequired
protected boolean checkRequired(MethodParameter parameter)
handleReturnValue
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
从接口复制的说明:HandlerMethodReturnValueHandler
Handle the given return value by adding attributes to the model and setting a view or setting theModelAndViewContainer.setRequestHandled(boolean)
flag totrue
to indicate the response has been handled directly.- 参数:
returnValue
- the value returned from the handler methodreturnType
- the type of the return value. This type must have previously been passed toHandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
which must have returnedtrue
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current request- 抛出:
IOException
HttpMediaTypeNotAcceptableException
HttpMessageNotWritableException