类 AbstractMessageConverterMethodProcessor
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
- org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
public abstract class AbstractMessageConverterMethodProcessor extends AbstractMessageConverterMethodArgumentResolver implements HandlerMethodReturnValueHandler
ExtendsAbstractMessageConverterMethodArgumentResolver
with the ability to handle method return values by writing to the response withHttpMessageConverters
.- 从以下版本开始:
- 3.1
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
allSupportedMediaTypes, logger, messageConverters
构造器概要
构造器 限定符 构造器 说明 protected
AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters)
Constructor with list of converters only.protected
AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager contentNegotiationManager)
Constructor with list of converters and ContentNegotiationManager.protected
AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice)
Constructor with list of converters and ContentNegotiationManager as well as request/response body advice instances.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected ServletServerHttpResponse
createOutputMessage(NativeWebRequest webRequest)
Creates a newHttpOutputMessage
from the givenNativeWebRequest
.protected List<MediaType>
getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass)
Returns the media types that can be produced.protected List<MediaType>
getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, Type targetType)
Returns the media types that can be produced.protected Class<?>
getReturnValueType(Object value, MethodParameter returnType)
Return the type of the value to be written to the response.protected boolean
isResourceType(Object value, MethodParameter returnType)
Return whether the returned value or the declared return type extendsResource
.protected <T> void
writeWithMessageConverters(T value, MethodParameter returnType, ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage)
Writes the given return type to the given output message.protected <T> void
writeWithMessageConverters(T value, MethodParameter returnType, NativeWebRequest webRequest)
Writes the given return value to the given web request.从类继承的方法 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver
adaptArgumentIfNecessary, createInputMessage, isBindExceptionRequired, readWithMessageConverters, readWithMessageConverters, validateIfApplicable
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.web.method.support.HandlerMethodArgumentResolver
resolveArgument, supportsParameter
从接口继承的方法 org.springframework.web.method.support.HandlerMethodReturnValueHandler
handleReturnValue, supportsReturnType
构造器详细资料
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters)
Constructor with list of converters only.
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, @Nullable ContentNegotiationManager contentNegotiationManager)
Constructor with list of converters and ContentNegotiationManager.
AbstractMessageConverterMethodProcessor
protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>> converters, @Nullable ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice)
Constructor with list of converters and ContentNegotiationManager as well as request/response body advice instances.
方法详细资料
createOutputMessage
protected ServletServerHttpResponse createOutputMessage(NativeWebRequest webRequest)
Creates a newHttpOutputMessage
from the givenNativeWebRequest
.- 参数:
webRequest
- the web request to create an output message from- 返回:
- the output message
writeWithMessageConverters
protected <T> void writeWithMessageConverters(T value, MethodParameter returnType, NativeWebRequest webRequest) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
Writes the given return value to the given web request. Delegates towriteWithMessageConverters(Object, MethodParameter, ServletServerHttpRequest, ServletServerHttpResponse)
writeWithMessageConverters
protected <T> void writeWithMessageConverters(@Nullable T value, MethodParameter returnType, ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException
Writes the given return type to the given output message.- 参数:
value
- the value to write to the output messagereturnType
- the type of the valueinputMessage
- the input messages. Used to inspect theAccept
header.outputMessage
- the output message to write to- 抛出:
IOException
- thrown in case of I/O errorsHttpMediaTypeNotAcceptableException
- thrown when the conditions indicated by theAccept
header on the request cannot be met by the message convertersHttpMessageNotWritableException
- thrown if a given message cannot be written by a converter, or if the content-type chosen by the server has no compatible converter.
getReturnValueType
protected Class<?> getReturnValueType(@Nullable Object value, MethodParameter returnType)
Return the type of the value to be written to the response. Typically this is a simple check via getClass on the value but if the value is null, then the return type needs to be examined possibly including generic type determination (e.g.ResponseEntity<T>
).
isResourceType
protected boolean isResourceType(@Nullable Object value, MethodParameter returnType)
Return whether the returned value or the declared return type extendsResource
.
getProducibleMediaTypes
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass)
Returns the media types that can be produced.
getProducibleMediaTypes
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, @Nullable Type targetType)
Returns the media types that can be produced. The resulting media types are:- The producible media types specified in the request mappings, or
- Media types of configured converters that can write the specific return value, or
MediaType.ALL
- 从以下版本开始:
- 4.2