接口定义
public interface RequestEntityResolverAdvice {
/**
* This method will be called around
* {@link RequestEntityResolver#readFrom(RequestEntity, RequestContext)}.
*
* @param context context
* @return object resolved value
* @throws Exception exception
*/
Object aroundRead(RequestEntityResolverContext context) throws Exception;
}
自定义RequestEntityResolverAdvice
与RequestEntityResolver
相同,RequestEntityResolverAdvice
自定应时同样需要实现RequestEntityResolverAdviceAdapter
或RequestEntityResolverAdviceFactory
接口
方式1 实现RequestEntityResolverAdviceAdapter
接口定义
public interface RequestEntityResolverAdviceAdapter extends RequestEntityResolverAdvice,
ParamPredicate, Ordered {
@Override
default boolean supports(Param param) {
return true;
}
@Override
default int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}
方式2:实现RequestEntityResolverAdviceFactory
接口定义
public interface RequestEntityResolverAdviceFactory extends ParamPredicate, Ordered {
/**
* 生成RequestEntityResolverAdvice
*/
RequestEntityResolverAdvice createResolverAdvice(Param param);
@Override
default int getOrder() {
return HIGHEST_PRECEDENCE;
}
}
RequestEntityResolverAdviceAdapter
接口以及RequestEntityResolverAdviceFactory
接口与RequestEntityResolver
中的RequestEntityResolverAdapter
接口以及RequestEntityResolverFactory
接口的使用方式相同,这里不过多赘述。