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

相关推荐
楚国的小隐士8 分钟前
为什么说Rust是对自闭症谱系人士友好的编程语言?
java·rust·编程·对比·自闭症·自闭症谱系障碍·神经多样性
春花秋月夏海冬雪31 分钟前
代码随想录刷题 - 贪心Part1
java·算法·贪心·代码随想录
野生技术架构师35 分钟前
2026年牛客网最新Java面试题总结
java·开发语言
Mr_Xuhhh1 小时前
深入理解Java抽象类与接口:从概念到实战
java·开发语言
wb043072011 小时前
使用 Java 开发 MCP 服务并发布到 Maven 中央仓库完整指南
java·开发语言·spring boot·ai·maven
Rsun045511 小时前
设计模式应该怎么学
java·开发语言·设计模式
5系暗夜孤魂2 小时前
系统越复杂,越需要“边界感”:从 Java 体系理解大型工程的可维护性本质
java·开发语言
二月夜2 小时前
Spring循环依赖深度解析:从三级缓存原理到跨环境“灵异”现象
java·spring
nbwenren2 小时前
Springboot中SLF4J详解
java·spring boot·后端
wellc3 小时前
java进阶知识点
java·开发语言