RequestBodyAdvice和ResponseBodyAdvice是干什么的

RequestBodyAdvice和ResponseBodyAdvice

有两个接口

RequestBodyAdvice 和ResponseBodyAdvice 在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多平台发布

相关推荐
香蕉大香蕉(06敬畏市场)4 分钟前
MySQL 单点详解(09)
java·数据库·mysql·面试·八股·大厂实习
吹什么轩43 分钟前
constexpr 完全指南:从 const 的两种含义,到编译期计算的四次演进
java·前端·javascript
她的男孩1 小时前
租户 A 的验证码,却用了租户 B 的 AccessKey:Forge Admin 修跨租户短信串发
java·spring boot·saas
LabVIEW开发1 小时前
LabVIEW 局部变量与数据流:这道 CLAD 题为什么答案是 Undefined
java·开发语言·labview
文丑颜不良啊1 小时前
LeetCode1721~1740题目解析
java·leetcode
wangbing11251 小时前
监控网页项目常用英文缩写
java
麻瓜code1 小时前
双写一致性:为什么是“删缓存“,而不是“改缓存“
java·缓存·mybatis
小蒜学长1 小时前
基于SpringBoot+Vue的云南地区扶贫助农系统的设计与实现(代码+数据库+LW)
java·vue.js·spring boot·后端·乡村振兴
砚底藏山河1 小时前
量化回测可复现流水线CI化
java·python·ci/cd·金融
骑着蜗牛撵大象3271 小时前
Spring Boot 4.1 + Spring AI 2.0:RAG 供文、图谱供关系、MCP 供工具的 Java Agent 平台
java·spring boot·spring·微服务·知识图谱·rag·mcp