ArgumentResolver

简要描述:

  • controller方法参数解析器,在所有controller方法都用共同的方法参数的共性时,可以利用此统一解析,针对参数类型,注解,参数值各种方式

example1:

  public class ClientInfoRequestArgumentResolver implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return MiniappClientInfo.class == parameter.getParameterType();
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
            NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        if (webRequest.getAttribute(ReqAttributes.CLIENTINFO, RequestAttributes.SCOPE_REQUEST) != null) {
            MiniappClientInfo clientInfo = (MiniappClientInfo) webRequest.getAttribute(ReqAttributes.CLIENTINFO,
                    RequestAttributes.SCOPE_REQUEST);
            return clientInfo;
        }
        return null;
    }


2.controller代码:
public JsonResp creditStage(WebAuthUser user, MiniappClientInfo ){

//doSomething();

}

3.配置
@Override
 public void addArgumentResolvers(List argumentResolvers) {
    
    argumentResolvers.add(new ClientInfoRequestArgumentResolver());

}

你可能感兴趣的:(ArgumentResolver)