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多平台发布

相关推荐
Frostnova丶7 小时前
LeetCode 190.颠倒二进制位
java·算法·leetcode
闻哥7 小时前
Redis事务详解
java·数据库·spring boot·redis·缓存·面试
hrhcode7 小时前
【Netty】五.ByteBuf内存管理深度剖析
java·后端·spring·springboot·netty
道亦无名8 小时前
aiPbMgrSendAck
java·网络·数据库
发现你走远了8 小时前
Windows 下手动安装java JDK 21 并配置环境变量(详细记录)
java·开发语言·windows
心 -8 小时前
java八股文DI
java
黎雁·泠崖9 小时前
Java常用类核心详解(一):Math 类超细讲解
java·开发语言
大尚来也9 小时前
跨平台全局键盘监听实战:基于 JNativeHook 在 Java 中捕获 Linux 键盘事件
java·linux
追随者永远是胜利者9 小时前
(LeetCode-Hot100)15. 三数之和
java·算法·leetcode·职场和发展·go
懒惰成性的9 小时前
12.Java的异常
java·开发语言