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

相关推荐
OtIo TALL3 小时前
redis7 for windows的安装教程
java
uNke DEPH4 小时前
Spring Boot的项目结构
java·spring boot·后端
xixingzhe24 小时前
idea启动vue项目
java·vue.js·intellij-idea
wzl202612135 小时前
企业微信定时群发技术实现与实操指南(原生接口+工具落地)
java·运维·前端·企业微信
凌波粒5 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
曹牧5 小时前
Eclipse:悬停提示(Hover)
java·ide·eclipse
oyzz1205 小时前
Spring EL 表达式的简单介绍和使用
java·后端·spring
iNgs IMAC6 小时前
Redis之Redis事务
java·数据库·redis
程序员小假6 小时前
向量检索的流程是怎样的?Embedding 和 Rerank 各自的作用?
java·后端
yaaakaaang6 小时前
二十二、模板方法模式
java·模板方法模式