接口定义
public interface ResponseEntityResolverAdvice {
/**
* This method will be called around
* {@link ResponseEntityResolver#writeTo(ResponseEntity, ResponseEntityChannel, RequestContext)}.
*
* @param context context
* @throws Exception exception
*/
void aroundWrite(ResponseEntityResolverContext context) throws Exception;
}
自定义ResponseEntityResolverAdvice
与ResponseEntityResolver
相同,ResponseEntityResolverAdvice
自定应时同样需要实现ResponseEntityResolverAdviceAdapter
或ResponseEntityResolverAdviceFactory
接口
方式1 实现ResponseEntityResolverAdviceAdapter
接口定义
public interface ResponseEntityResolverAdviceAdapter
extends HandlerPredicate, ResponseEntityResolverAdvice, Ordered {
@Override
default boolean supports(HandlerMethod method) {
return true;
}
@Override
default int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}
方式2:实现ResponseEntityResolverAdviceFactory
接口定义
public interface ResponseEntityResolverAdviceFactory extends ResponseEntityPredicate, Ordered {
/**
* 生成ResponseEntityResolverAdvice
*/
ResponseEntityResolverAdvice createResolverAdvice(HandlerMethod method);
@Override
default int getOrder() {
return HIGHEST_PRECEDENCE;
}
}
ResponseEntityResolverAdviceAdapter
接口以及ResponseEntityResolverAdviceFactory
接口与ResponseEntityResolver
中的ResponseEntityResolverAdapter
接口以及ResponseEntityResolverFactory
接口的使用方式相同,这里不过多赘述。