value ( )源码实例Demo

org.springframework.web.bind.annotation.PathVariable#value ( )源码实例Demo

下面列出了org.springframework.web.bind.annotation.PathVariable#value ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
		return;
	}

	PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
	String name = (ann != null && StringUtils.hasLength(ann.value()) ? ann.value() : parameter.getParameterName());
	String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
	uriVariables.put(name, formatted);
}
 
源代码2 项目: springdoc-openapi   文件: ParameterInfo.java
/**
 * Calculate name string.
 *
 * @param pName the p name
 * @param requestHeader the request header
 * @param requestParam the request param
 * @param pathVar the path var
 * @param cookieValue the cookie value
 * @return the string
 */
private String calculateName(String pName, RequestHeader requestHeader, RequestParam requestParam, PathVariable pathVar, CookieValue cookieValue) {
	String name = pName;
	if (requestHeader != null && StringUtils.isNotEmpty(requestHeader.value()))
		name = requestHeader.value();
	else if (requestParam != null && StringUtils.isNotEmpty(requestParam.value()))
		name = requestParam.value();
	else if (pathVar != null && StringUtils.isNotEmpty(pathVar.value()))
		name = pathVar.value();
	else if (cookieValue != null && StringUtils.isNotEmpty(cookieValue.value()))
		name = cookieValue.value();
	return name;
}
 
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
		return;
	}

	PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
	String name = (ann != null && !StringUtils.isEmpty(ann.value()) ? ann.value() : parameter.getParameterName());
	String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
	uriVariables.put(name, formatted);
}
 
@Override
public String getParameterName(PathVariable annotation) {
  String value = annotation.value();
  if (value.isEmpty()) {
    value = annotation.name();
  }
  return value;
}
 
源代码5 项目: lams   文件: PathVariableMethodArgumentResolver.java
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	if (Map.class.isAssignableFrom(parameter.nestedIfOptional().getNestedParameterType())) {
		return;
	}

	PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
	String name = (ann != null && !StringUtils.isEmpty(ann.value()) ? ann.value() : parameter.getParameterName());
	value = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
	uriVariables.put(name, value);
}
 
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	if (Map.class.isAssignableFrom(parameter.getParameterType())) {
		return;
	}

	PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
	String name = (ann == null || StringUtils.isEmpty(ann.value()) ? parameter.getParameterName() : ann.value());
	value = formatUriValue(conversionService, new TypeDescriptor(parameter), value);
	uriVariables.put(name, value);
}
 
源代码7 项目: lams   文件: HandlerMethodInvoker.java
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 SynthesizingMethodParameter(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.name();
				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;
}
 
public PathVariableNamedValueInfo(PathVariable annotation) {
	super(annotation.value(), true, ValueConstants.DEFAULT_NONE);
}
 
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 SynthesizingMethodParameter(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.name();
				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;
}
 
@Override
protected String getPath(PathVariable annot) {
    return annot.value();
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 同类方法