當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodParameter.getParameterName方法代碼示例

本文整理匯總了Java中org.springframework.core.MethodParameter.getParameterName方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodParameter.getParameterName方法的具體用法?Java MethodParameter.getParameterName怎麽用?Java MethodParameter.getParameterName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.MethodParameter的用法示例。


在下文中一共展示了MethodParameter.getParameterName方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: contributeMethodArgument

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class.equals(paramType) ||
			"javax.servlet.http.Part".equals(paramType.getName())) {
		return;
	}

	RequestParam annot = parameter.getParameterAnnotation(RequestParam.class);
	String name = StringUtils.isEmpty(annot.value()) ? parameter.getParameterName() : annot.value();

	if (value == null) {
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:RequestParamMethodArgumentResolver.java

示例2: getHttpEntityType

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
private Class<?> getHttpEntityType(MethodParameter methodParam) {
	Assert.isAssignable(HttpEntity.class, methodParam.getParameterType());
	ParameterizedType type = (ParameterizedType) methodParam.getGenericParameterType();
	if (type.getActualTypeArguments().length == 1) {
		Type typeArgument = type.getActualTypeArguments()[0];
		if (typeArgument instanceof Class) {
			return (Class<?>) typeArgument;
		}
		else if (typeArgument instanceof GenericArrayType) {
			Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType();
			if (componentType instanceof Class) {
				// Surely, there should be a nicer way to do this
				Object array = Array.newInstance((Class<?>) componentType, 0);
				return array.getClass();
			}
		}
	}
	throw new IllegalArgumentException(
			"HttpEntity parameter (" + methodParam.getParameterName() + ") is not parameterized");

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:HandlerMethodInvoker.java

示例3: contributeMethodArgument

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
    Class<?> paramType = parameter.getNestedParameterType();
    if (Map.class.isAssignableFrom(paramType)) {
        return;
    }
    WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
    String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
    WxAppAssert.notNull(name, "請添加編譯器的-parameter或者為參數添加注解名稱");
    if (value == null) {
        if (wxApiParam != null) {
            if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
                return;
            }
        }
        builder.queryParam(name);
    } else if (value instanceof Collection) {
        for (Object element : (Collection<?>) value) {
            element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
            builder.queryParam(name, element);
        }
    } else {
        builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:26,代碼來源:WxApiParamContributor.java

示例4: 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

示例5: resolveArgument

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                              NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
        throws Exception {

    String body = getRequestBody(webRequest);
    String value = parameter.getParameterAnnotation(JsonParameter.class).value();
    if (StringUtils.isBlank(value)) {
        value = parameter.getParameterName();
    }

    return parameterParser.parse(body, value, parameter);
}
 
開發者ID:guqiyao,項目名稱:fishing-village,代碼行數:14,代碼來源:JsonParameterResolver.java

示例6: updateNamedValueInfo

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
	String name = info.name;
	if (info.name.length() == 0) {
		name = parameter.getParameterName();
		Assert.notNull(name, "Name for argument type [" + parameter.getParameterType().getName()
					+ "] not available, and parameter name information not found in class file either.");
	}
	String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
	return new NamedValueInfo(name, info.required, defaultValue);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:AbstractNamedValueMethodArgumentResolver.java

示例7: readWithMessageConverters

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class<?> paramType)
		throws Exception {

	MediaType contentType = inputMessage.getHeaders().getContentType();
	if (contentType == null) {
		StringBuilder builder = new StringBuilder(ClassUtils.getShortName(methodParam.getParameterType()));
		String paramName = methodParam.getParameterName();
		if (paramName != null) {
			builder.append(' ');
			builder.append(paramName);
		}
		throw new HttpMediaTypeNotSupportedException(
				"Cannot extract parameter (" + builder.toString() + "): no Content-Type found");
	}

	List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
	if (this.messageConverters != null) {
		for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
			allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
			if (messageConverter.canRead(paramType, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + paramType.getName() + "] as \"" + contentType
							+"\" using [" + messageConverter + "]");
				}
				return messageConverter.read((Class) paramType, inputMessage);
			}
		}
	}
	throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:HandlerMethodInvoker.java

示例8: getRequiredParameterName

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
private String getRequiredParameterName(MethodParameter methodParam) {
	String name = methodParam.getParameterName();
	if (name == null) {
		throw new IllegalStateException(
				"No parameter name specified for argument of type [" + methodParam.getParameterType().getName() +
						"], and no parameter name information found in class file either.");
	}
	return name;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:HandlerMethodInvoker.java

示例9: resolveArgument

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
                              NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    String body = getRequestBody(webRequest);
    String arg = parameter.getParameterAnnotation(JsonArg.class).value();
    if (StringUtils.isEmpty(arg)) {
        arg = parameter.getParameterName();
    }
    return JsonPath.parse(body).read(arg, parameter.getParameterType());
}
 
開發者ID:mingzuozhibi,項目名稱:mzzb-server,代碼行數:10,代碼來源:JsonArgumentResolver.java

示例10: contributeMethodArgument

import org.springframework.core.MethodParameter; //導入方法依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
                                     UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
    if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
        return;
    }
    WxApiPath wx = parameter.getParameterAnnotation(WxApiPath.class);
    String name = (wx != null && !StringUtils.isEmpty(wx.value()) ? wx.value() : parameter.getParameterName());
    WxAppAssert.notNull(name, "請添加編譯器的-parameter或者為參數添加注解名稱");
    value = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
    uriVariables.put(name, value);
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:13,代碼來源:WxApiPathContributor.java

示例11: 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


注:本文中的org.springframework.core.MethodParameter.getParameterName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。