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

接口定义

public interface ParamResolverAdvice {

    /**
     * This method is called around {@link ParamResolver#resolve(RequestContext)}.
     *
     * @param context context
     * @return resolved arg value
     * @throws Exception exception
     */
    Object aroundResolve(ParamResolverContext context) throws Exception;

}

自定义ParamResolverAdvice

ParamResolver相同,ParamResolverAdvice自定应时同样需要实现ParamResolverAdviceAdapterParamResolverAdviceFactory接口

方式1:实现 ParamResolverAdviceAdapter

接口定义

public interface ParamResolverAdviceAdapter extends ParamPredicate, ParamResolverAdvice, Ordered {

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

方式2:实现ParamResolverAdviceFactory

接口定义

public interface ParamResolverAdviceFactory extends ParamPredicate, Ordered {
    /**
     * Creates an instance of {@link ParamResolverAdvice} for given handler method.
     *
     * @param param    method
     * @param resolver paramResolver associated with this parameter
     * @return advice
     */
    ParamResolverAdvice createResolverAdvice(Param param, ParamResolver resolver);
}

ParamResolverAdviceAdapter接口以及ParamResolverAdviceFactory接口与ParamResolver中的ParamResolverAdapter接口以及ParamResolverFactory接口的使用方式相同,这里不过多赘述。