RequestBodyAdvice和ResponseBodyAdvice是干什么的

RequestBodyAdvice和ResponseBodyAdvice

有两个接口

RequestBodyAdviceResponseBodyAdvice 在spring4中新添加的两个接口

RequestBodyAdvice接口

该接口是在获取@RequestBody参数数据之前进行处理的

java 复制代码
public interface RequestBodyAdvice {

   
   boolean supports(MethodParameter methodParameter, Type targetType,
         Class<? extends HttpMessageConverter<?>> converterType);

   
   Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
         Type targetType, Class<? extends HttpMessageConverter<?>> converterType);

   
   HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter,
         Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException;

   
   Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
         Type targetType, Class<? extends HttpMessageConverter<?>> converterType);

}

ResponseBodyAdvice接口

该接口是在消息体被HttpMessageConverter消息解析器写入之前执行的

java 复制代码
public interface ResponseBodyAdvice<T> {

   
   boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType);

   
   T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType,
         Class<? extends HttpMessageConverter<?>> selectedConverterType,
         ServerHttpRequest request, ServerHttpResponse response);

}

zhhll.icu/2021/框架/spr...

本文由mdnice多平台发布

相关推荐
win x14 分钟前
Redis 使用~如何在Java中连接使用redis
java·数据库·redis
星晨雪海20 分钟前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
阿维的博客日记27 分钟前
什么是逃逸分析
java·juc
Ricky_Theseus1 小时前
C++右值引用
java·开发语言·c++
Rick19931 小时前
Java内存参数解析
java·开发语言·jvm
我是大猴子1 小时前
Spring代理类为何依赖注入失效?
java·后端·spring
勿忘,瞬间1 小时前
多线程之进阶修炼
java·开发语言
014-code2 小时前
线程池参数怎么配才不翻车
java
吴梓穆2 小时前
UE5 c++ 常用方法
java·c++·ue5
王夏奇2 小时前
python中的__all__ 具体用法
java·前端·python