接口 ResponseBodyAdvice<T>
- 所有已知实现类:
AbstractJsonpResponseBodyAdvice,AbstractMappingJacksonResponseBodyAdvice,JsonViewResponseBodyAdvice
public interface ResponseBodyAdvice<T>
Allows customizing the response after the execution of an@ResponseBodyor aResponseEntitycontroller method but before the body is written with anHttpMessageConverter.Implementations may be registered directly with
RequestMappingHandlerAdapterandExceptionHandlerExceptionResolveror more likely annotated with@ControllerAdvicein which case they will be auto-detected by both.- 从以下版本开始:
- 4.1
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 TbeforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response)Invoked after anHttpMessageConverteris selected and just before its write method is invoked.booleansupports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.
方法详细资料
supports
boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)
Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.- 参数:
returnType- the return typeconverterType- the selected converter type- 返回:
trueifbeforeBodyWrite(T, org.springframework.core.MethodParameter, org.springframework.http.MediaType, java.lang.Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>, org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse)should be invoked;falseotherwise
beforeBodyWrite
T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response)
Invoked after anHttpMessageConverteris selected and just before its write method is invoked.- 参数:
body- the body to be writtenreturnType- the return type of the controller methodselectedContentType- the content type selected through content negotiationselectedConverterType- the converter type selected to write to the responserequest- the current requestresponse- the current response- 返回:
- the body that was passed in or a modified (possibly new) instance