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

相关推荐
吴声子夜歌2 分钟前
Guava——并发(一)
java·guava
天空属于哈夫克35 分钟前
企业微信API:企业微信如何实现自动化运营?
java·自动化·企业微信
lhldsg14 分钟前
相册印刷实战指南:从设计规范到系统落地全流程解析
java·小程序·架构·设计规范
草青工作室17 分钟前
java-不携带Token也能“打“自己的接口:一个绕开网关鉴权、用 URL 直接调度 SpringMVC 方法的轻量级定时任务方案
java·开发语言
霸道流氓气质23 分钟前
Spring AI提示词模板与动态变量替换
java·python·spring
Object_SC25 分钟前
java 中的泛型
java
s_w.h38 分钟前
【 linux 】线程互斥与同步
java·linux·服务器·开发语言
学长毕业设计39 分钟前
基于SpringBoot的校园二手物品交易系统(源码+文档+讲解视频)
java·spring boot·后端
观无1 小时前
若依AOP
java
是2的10次方啊1 小时前
日志不是越多越好:开发优化、常见坑与线上排查命令
java