接口 ResponseBodyAdvice<T>
- 类型参数:
T- the body type
- 所有已知实现类:
AbstractMappingJacksonResponseBodyAdvice,JsonViewResponseBodyAdvice,RequestResponseBodyAdviceChain
public interface ResponseBodyAdvice<T>
Allows customizing the response after the execution of an
@ResponseBody
or a ResponseEntity controller method but before the body is written
with an HttpMessageConverter.
Implementations may be registered directly with
RequestMappingHandlerAdapter and ExceptionHandlerExceptionHandler
or more likely annotated with @ControllerAdvice in which case they
will be auto-detected by both.
- 从以下版本开始:
- 4.0 2022/1/22 21:43
- 作者:
- Rossen Stoyanchev, Harry Yang
-
方法概要
修饰符和类型方法说明beforeBodyWrite(Object body, cn.taketoday.core.MethodParameter returnType, MediaType contentType, HttpMessageConverter<?> converter, RequestContext context) Invoked after anHttpMessageConverteris selected and just before its write method is invoked.booleansupports(Object body, cn.taketoday.core.MethodParameter returnType, HttpMessageConverter<?> converter) Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.
-
方法详细资料
-
supports
boolean supports(@Nullable Object body, @Nullable cn.taketoday.core.MethodParameter returnType, HttpMessageConverter<?> converter) Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.- 参数:
returnType- the return typeconverter- the selected converter- 返回:
trueifbeforeBodyWrite(java.lang.Object, cn.taketoday.core.MethodParameter, cn.taketoday.http.MediaType, cn.taketoday.http.converter.HttpMessageConverter<?>, cn.taketoday.web.RequestContext)should be invoked;falseotherwise
-
beforeBodyWrite
@Nullable T beforeBodyWrite(@Nullable Object body, @Nullable cn.taketoday.core.MethodParameter returnType, MediaType contentType, HttpMessageConverter<?> converter, RequestContext context) Invoked after anHttpMessageConverteris selected and just before its write method is invoked.- 参数:
body- the body to be writtenreturnType- the return type of the controller methodcontentType- the content type selected through content negotiationconverter- the converter selected to write to the responsecontext- the current request context- 返回:
- the body that was passed in or a modified (possibly new) instance
-