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

相关推荐
大阿明10 小时前
Spring Boot(快速上手)
java·spring boot·后端
bearpping10 小时前
Java进阶,时间与日期,包装类,正则表达式
java
邵奈一10 小时前
清明纪念·时光信笺——项目运行指南
java·实战·项目
sunwenjian88611 小时前
Java进阶——IO 流
java·开发语言·python
sinat_2554878111 小时前
读者、作家 Java集合学习笔记
java·笔记·学习
皮皮林55111 小时前
如何画出一张优秀的架构图?(老鸟必备)
java
百锦再11 小时前
Java 并发编程进阶,从线程池、锁、AQS 到并发容器与性能调优全解析
java·开发语言·jvm·spring·kafka·tomcat·maven
森林猿11 小时前
java-modbus-读取-modbus4j
java·网络·python
tobias.b12 小时前
计算机基础知识-数据结构
java·数据结构·考研
reembarkation12 小时前
光标在a-select,鼠标已经移出,下拉框跟随页面滚动
java·数据库·sql