当前位置: 首页>>代码示例>>Java>>正文


Java MethodParameter.initParameterNameDiscovery方法代码示例

本文整理汇总了Java中org.springframework.core.MethodParameter.initParameterNameDiscovery方法的典型用法代码示例。如果您正苦于以下问题:Java MethodParameter.initParameterNameDiscovery方法的具体用法?Java MethodParameter.initParameterNameDiscovery怎么用?Java MethodParameter.initParameterNameDiscovery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.MethodParameter的用法示例。


在下文中一共展示了MethodParameter.initParameterNameDiscovery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyContributors

import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
    CompositeUriComponentsContributor contributor = defaultUriComponentsContributor;
    int paramCount = method.getParameterTypes().length;
    int argCount = args.length;
    if (paramCount != argCount) {
        throw new IllegalArgumentException("方法参数量为" + paramCount + " 与真实参数量不匹配,真实参数量为" + argCount);
    }
    final Map<String, Object> uriVars = new HashMap<>(8);
    for (int i = 0; i < paramCount; i++) {
        MethodParameter param = new SynthesizingMethodParameter(method, i);
        param.initParameterNameDiscovery(parameterNameDiscoverer);
        contributor.contributeMethodArgument(param, args[i], builder, uriVars);
    }
    // We may not have all URI var values, expand only what we have
    return builder.build().expand(name -> uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:17,代码来源:WxApiMethodInfo.java

示例2: getParameterName

import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
public static String getParameterName(Method method, int paramIdx) {
  MethodParameter methodParameter = new MethodParameter(method, paramIdx);
  methodParameter.initParameterNameDiscovery(parameterNameDiscoverer);

  String paramName = methodParameter.getParameterName();
  if (paramName == null) {
    // 小于jdk8的场景中,即使有debug参数,也无法对着interface获取参数名,此时直接使用arg + paramIndex来表示
    paramName = "arg" + paramIdx;
  }
  return paramName;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:12,代码来源:ParamUtils.java

示例3: getMethodArgumentValues

import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
/**
 * Get the method argument values for the current request.
 */
private Object[] getMethodArgumentValues(NativeWebRequest request, ModelAndViewContainer mavContainer,
		Object... providedArgs) throws Exception {

	MethodParameter[] parameters = getMethodParameters();
	Object[] args = new Object[parameters.length];
	for (int i = 0; i < parameters.length; i++) {
		MethodParameter parameter = parameters[i];
		parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
		GenericTypeResolver.resolveParameterType(parameter, getBean().getClass());
		args[i] = resolveProvidedArgument(parameter, providedArgs);
		if (args[i] != null) {
			continue;
		}
		if (this.argumentResolvers.supportsParameter(parameter)) {
			try {
				args[i] = this.argumentResolvers.resolveArgument(
						parameter, mavContainer, request, this.dataBinderFactory);
				continue;
			}
			catch (Exception ex) {
				if (logger.isTraceEnabled()) {
					logger.trace(getArgumentResolutionErrorMessage("Error resolving argument", i), ex);
				}
				throw ex;
			}
		}
		if (args[i] == null) {
			String msg = getArgumentResolutionErrorMessage("No suitable resolver for argument", i);
			throw new IllegalStateException(msg);
		}
	}
	return args;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:InvocableHandlerMethod.java

示例4: getMethodArgumentValues

import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Object[] getMethodArgumentValues(WampMessage message, List<Object> arguments,
		Map<String, Object> argumentsKw) throws Exception {

	MethodParameter[] parameters = getMethodParameters();
	Object[] args = new Object[parameters.length];
	int argIndex = 0;
	for (int i = 0; i < parameters.length; i++) {
		MethodParameter parameter = parameters[i];
		parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);

		if (this.argumentResolvers.supportsParameter(parameter)) {
			try {
				args[i] = this.argumentResolvers.resolveArgument(parameter, message);
				continue;
			}
			catch (Exception ex) {
				if (this.logger.isDebugEnabled()) {
					this.logger.debug(
							getArgumentResolutionErrorMessage("Failed to resolve", i),
							ex);
				}
				throw ex;
			}
		}

		if (arguments != null && arguments.size() > argIndex) {
			args[i] = convert(parameter, arguments.get(argIndex));
			if (args[i] != null) {
				argIndex++;
				continue;
			}
		}

		if (argumentsKw != null) {
			String paramName = parameter.getParameterName();
			if (paramName != null) {
				Object arg = argumentsKw.get(paramName);
				if (arg != null) {
					args[i] = convert(parameter, arg);
					continue;
				}
			}
		}

		if (args[i] == null) {
			throw new MethodArgumentResolutionException(message, parameter,
					getArgumentResolutionErrorMessage("No suitable resolver for", i));
		}
	}

	return args;
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:53,代码来源:InvocableHandlerMethod.java

示例5: resolveInitBinderArguments

import org.springframework.core.MethodParameter; //导入方法依赖的package包/类
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod,
		WebDataBinder binder, NativeWebRequest webRequest) throws Exception {

	Class<?>[] initBinderParams = initBinderMethod.getParameterTypes();
	Object[] initBinderArgs = new Object[initBinderParams.length];

	for (int i = 0; i < initBinderArgs.length; i++) {
		MethodParameter methodParam = new MethodParameter(initBinderMethod, i);
		methodParam.initParameterNameDiscovery(this.parameterNameDiscoverer);
		GenericTypeResolver.resolveParameterType(methodParam, handler.getClass());
		String paramName = null;
		boolean paramRequired = false;
		String paramDefaultValue = null;
		String pathVarName = null;
		Annotation[] paramAnns = methodParam.getParameterAnnotations();

		for (Annotation paramAnn : paramAnns) {
			if (RequestParam.class.isInstance(paramAnn)) {
				RequestParam requestParam = (RequestParam) paramAnn;
				paramName = requestParam.value();
				paramRequired = requestParam.required();
				paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
				break;
			}
			else if (ModelAttribute.class.isInstance(paramAnn)) {
				throw new IllegalStateException(
						"@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
			}
			else if (PathVariable.class.isInstance(paramAnn)) {
				PathVariable pathVar = (PathVariable) paramAnn;
				pathVarName = pathVar.value();
			}
		}

		if (paramName == null && pathVarName == null) {
			Object argValue = resolveCommonArgument(methodParam, webRequest);
			if (argValue != WebArgumentResolver.UNRESOLVED) {
				initBinderArgs[i] = argValue;
			}
			else {
				Class<?> paramType = initBinderParams[i];
				if (paramType.isInstance(binder)) {
					initBinderArgs[i] = binder;
				}
				else if (BeanUtils.isSimpleProperty(paramType)) {
					paramName = "";
				}
				else {
					throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
							"] for @InitBinder method: " + initBinderMethod);
				}
			}
		}

		if (paramName != null) {
			initBinderArgs[i] =
					resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
		}
		else if (pathVarName != null) {
			initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
		}
	}

	return initBinderArgs;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:66,代码来源:HandlerMethodInvoker.java


注:本文中的org.springframework.core.MethodParameter.initParameterNameDiscovery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。