接口 RequestBodyAdvice
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 anHttpEntity
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.2
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 Object
afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked third (and last) after the request body is converted to an Object.HttpInputMessage
beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked second before the request body is read and converted.Object
handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked second (and last) if the body is empty.boolean
supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked first to determine if this interceptor applies.
方法详细资料
supports
boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked first to determine if this interceptor applies.- 参数:
methodParameter
- the method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.converterType
- the selected converter type- 返回:
- whether this interceptor should be invoked or not
handleEmptyBody
Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked second (and last) if the body is empty.- 参数:
body
- set tonull
before the first advice is calledinputMessage
- the requestparameter
- the method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.converterType
- the selected converter type- 返回:
- the value to use or
null
which may then raise anHttpMessageNotReadableException
if the argument is required.
beforeBodyRead
HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException
Invoked second before the request body is read and converted.- 参数:
inputMessage
- the requestparameter
- the target method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.converterType
- the converter used to deserialize the body- 返回:
- the input request or a new instance, never
null
- 抛出:
IOException
afterBodyRead
Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType)
Invoked third (and last) after the request body is converted to an Object.- 参数:
body
- set to the converter Object before the 1st advice is calledinputMessage
- the requestparameter
- the target method parametertargetType
- the target type, not necessarily the same as the method parameter type, e.g. forHttpEntity<String>
.converterType
- the converter used to deserialize the body- 返回:
- the same body or a new instance