ReturnValueResolverAdvice
ReturnValueResolverAdvice
允许用户在ReturnValueResolver
参数解析器解析参数的前后添加业务逻辑以及修改解析后的参数。接口定义
public interface ReturnValueResolverAdvice {
/**
* 使用此方法的返回值作为ReturnValueResolver.resolve()的参数调用
*/
Object beforeResolve(Object returnValue, AsyncRequest request, AsyncResponse response);
}
自定义ReturnValueResolverAdvice
与ArgumentResovler
相同, ReturnValueResolverAdvice
自定应时同样需要实现ReturnValueResolverAdviceAdapter
或ReturnValueResolverAdviceFactory
接口
方式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
接口的使用方式相同, 这里不过多赘述。
Note
ReturnValueResolverAdvice
与ReturnValueResolver
生命周期是相同的, 即应用初始化的时候便会决定每个参数的ReturnValueResolverAdvice
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified March 10, 2022: introduce docsy as the website framework and add docs-v1.0.0 (#120) (79630ff)