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 分钟前
任务调度功能实现
java·开发语言·spring boot
想你的液宝11 分钟前
Spring Boot 中基于 AOP 的 Controller 统一日志打印方案
java·后端
天草二十六_简村人16 分钟前
阿里云SLS采集jvm日志(上)
java·运维·数据库·后端·阿里云·容器·云计算
_MyFavorite_24 分钟前
JAVA重点基础、进阶知识及易错点总结(15)缓冲流 + 转换流
java·开发语言·spring boot
qq_3331209743 分钟前
头歌答案--爬虫实战
java·前端·爬虫
TT哇1 小时前
【项目】从“本地能跑”到“生产级部署”:Java + Docker 自动化部署深度复盘
java·docker·自动化
摇滚侠1 小时前
JAVA 项目教程《苍穹外卖-11》,微信小程序项目,前后端分离,从开发到部署
java·开发语言·微信小程序
muls11 小时前
java面试宝典
java·linux·服务器·网络·算法·操作系统
执笔论英雄1 小时前
【vllm】vllm根据并发学习调度
java·学习·vllm
瑶总迷弟1 小时前
Python入门第6章:字典(键值对数据结构)
java·数据结构·python