ReturnValueResolverAdvice

ReturnValueResolverAdvice允许用户在ReturnValueResolver参数解析器解析参数的前后添加业务逻辑以及修改解析后的参数。

接口定义

public interface ReturnValueResolverAdvice {
    /**
     * 使用此方法的返回值作为ReturnValueResolver.resolve()的参数调用
     */
    Object beforeResolve(Object returnValue, AsyncRequest request, AsyncResponse response);
}

自定义ReturnValueResolverAdvice

ArgumentResovler相同, ReturnValueResolverAdvice自定应时同样需要实现ReturnValueResolverAdviceAdapterReturnValueResolverAdviceFactory接口

方式1 实现ReturnValueResolverAdviceAdapter

接口定义

public interface ReturnValueResolverAdviceAdapter
        extends ReturnValueResolverPredicate, ReturnValueResolverAdvice, Ordered {

    @Override
    default Object beforeResolve(Object returnValue, AsyncRequest request, AsyncResponse response) {
        return returnValue;
    }

    @Override
    default int getOrder() {
        return HIGHEST_PRECEDENCE;
    }
}

方式2:实现ReturnValueResolverAdviceFactory

接口定义

public interface ReturnValueResolverAdviceFactory extends ReturnValueResolverPredicate, Ordered {
    /**
     * 生成ReturnValueResolverAdvice
     */
    ReturnValueResolverAdvice createResolverAdvice(InvocableMethod method, ReturnValueResolver resolver);

    @Override
    default int getOrder() {
        return HIGHEST_PRECEDENCE;
    }
}

ReturnValueResolverAdviceAdapter接口以及ReturnValueResolverAdviceFactory接口与ReturnValueResolver中的ReturnValueResolverAdapter接口以及ReturnValueResolverFactory接口的使用方式相同, 这里不过多赘述。