接口定义

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自定应时同样需要实现ResponseEntityResolverAdviceAdapterResponseEntityResolverAdviceFactory接口

方式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接口的使用方式相同,这里不过多赘述。