接口 RequestBodyAdvice

所有已知实现类:
JsonViewRequestBodyAdvice, RequestResponseBodyAdviceChain

public interface RequestBodyAdvice
Allows customizing the request before its body is read and converted into an Object and also allows for processing of the resulting Object before it is passed into a controller method as an @RequestBody or an HttpEntity method argument.

Implementations of this contract may be registered directly with the RequestMappingHandlerAdapter or more likely annotated with @ControllerAdvice in which case they are auto-detected.

从以下版本开始:
4.0 2022/1/22 21:42
作者:
Rossen Stoyanchev, Harry Yang
  • 方法详细资料

    • supports

      boolean supports(cn.taketoday.core.MethodParameter methodParameter, Type targetType, HttpMessageConverter<?> converter)
      Invoked first to determine if this interceptor applies.
      参数:
      methodParameter - the method parameter
      targetType - the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
      converter - the selected converter
      返回:
      whether this interceptor should be invoked or not
    • beforeBodyRead

      HttpInputMessage beforeBodyRead(HttpInputMessage request, cn.taketoday.core.MethodParameter parameter, Type targetType, HttpMessageConverter<?> converter) throws IOException
      Invoked second before the request body is read and converted.
      参数:
      request - the request
      parameter - the target method parameter
      targetType - the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
      converter - the converter used to deserialize the body
      返回:
      the input request or a new instance (never null)
      抛出:
      IOException
    • afterBodyRead

      default Object afterBodyRead(Object body, HttpInputMessage inputMessage, cn.taketoday.core.MethodParameter parameter, Type targetType, HttpMessageConverter<?> converter)
      Invoked third (and last) after the request body is converted to an Object.
      参数:
      body - set to the converter Object before the first advice is called
      inputMessage - the request
      parameter - the target method parameter
      targetType - the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
      converter - the converter used to deserialize the body
      返回:
      the same body or a new instance
    • handleEmptyBody

      @Nullable default Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, cn.taketoday.core.MethodParameter parameter, Type targetType, HttpMessageConverter<?> converter)
      Invoked second (and last) if the body is empty.
      参数:
      body - usually set to null before the first advice is called
      inputMessage - the request
      parameter - the method parameter
      targetType - the target type, not necessarily the same as the method parameter type, e.g. for HttpEntity<String>.
      converter - the selected converter
      返回:
      the value to use, or null which may then raise an HttpMessageNotReadableException if the argument is required