Java Code Examples for org.springframework.web.bind.annotation.RequestParam#defaultValue()

The following examples show how to use org.springframework.web.bind.annotation.RequestParam#defaultValue() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Build params parameter.
 *
 * @param parameterInfo the parameter info
 * @param components the components
 * @param requestMethod the request method
 * @param jsonView the json view
 * @return the parameter
 */
public Parameter buildParams(ParameterInfo parameterInfo, Components components,
		RequestMethod requestMethod, JsonView jsonView) {
	MethodParameter methodParameter = parameterInfo.getMethodParameter();
	RequestHeader requestHeader = parameterInfo.getRequestHeader();
	RequestParam requestParam = parameterInfo.getRequestParam();
	PathVariable pathVar = parameterInfo.getPathVar();
	CookieValue cookieValue = parameterInfo.getCookieValue();

	RequestInfo requestInfo;

	if (requestHeader != null) {
		requestInfo = new RequestInfo(ParameterIn.HEADER.toString(), parameterInfo.getpName(), requestHeader.required(),
				requestHeader.defaultValue());
		return buildParam(parameterInfo, components, requestInfo, jsonView);

	}
	else if (requestParam != null && !parameterBuilder.isFile(parameterInfo.getMethodParameter())) {
		requestInfo = new RequestInfo(ParameterIn.QUERY.toString(), parameterInfo.getpName(), requestParam.required() && !methodParameter.isOptional(),
				requestParam.defaultValue());
		return buildParam(parameterInfo, components, requestInfo, jsonView);
	}
	else if (pathVar != null) {
		requestInfo = new RequestInfo(ParameterIn.PATH.toString(), parameterInfo.getpName(), !methodParameter.isOptional(), null);
		return buildParam(parameterInfo, components, requestInfo, jsonView);
	}
	else if (cookieValue != null) {
		requestInfo = new RequestInfo(ParameterIn.COOKIE.toString(), parameterInfo.getpName(), cookieValue.required(),
				cookieValue.defaultValue());
		return buildParam(parameterInfo, components, requestInfo, jsonView);
	}
	// By default
	DelegatingMethodParameter delegatingMethodParameter = (DelegatingMethodParameter) methodParameter;
	if (RequestMethod.GET.equals(requestMethod)
			|| (parameterInfo.getParameterModel() != null && (ParameterIn.PATH.toString().equals(parameterInfo.getParameterModel().getIn())))
			|| delegatingMethodParameter.isParameterObject())
		return this.buildParam(QUERY_PARAM, components, parameterInfo, !methodParameter.isOptional(), null, jsonView);

	return null;
}
 
Example 2
RequestParamNamedValueInfo(RequestParam annotation) {
	super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 3
public RequestParamNamedValueInfo(RequestParam annotation) {
	super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 4
RequestParamNamedValueInfo(RequestParam annotation) {
	super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 5
public RequestParamNamedValueInfo(RequestParam annotation) {
	super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 6
public RequestParamNamedValueInfo(RequestParam annotation) {
    super((annotation.name() != null && annotation.name() != "") ? annotation.name() : annotation.value(),
        annotation.required(), annotation.defaultValue());

}
 
Example 7
@Override
protected String pureReadDefaultValue(RequestParam requestParam) {
  return requestParam.defaultValue();
}
 
Example 8
public RequestParamNamedValueInfo(RequestParam annotation) {
	super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 9
public RequestParamNamedValueInfo(RequestParam annotation) {
    super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 10
public RequestParamNamedValueInfo(RequestParam annotation) {
	super(annotation.name(), annotation.required(), annotation.defaultValue());
}
 
Example 11
Source Project: onetwo   File: ApiClientMethod.java    License: Apache License 2.0 4 votes vote down vote up
protected void handleArg(MultiValueMap<String, Object> values, ApiClientMethodParameter mp, final Object pvalue, boolean parameterNameAsPrefix){
		if(pvalue instanceof ApiArgumentTransformer){
			Object val = ((ApiArgumentTransformer)pvalue).asApiValue();
			values.add(mp.getParameterName(), val);
			return ;
		}
		
		String prefix = "";
		Object paramValue = pvalue;
		//下列情况,强制使用名称作为前缀
		if(mp.hasParameterAnnotation(RequestParam.class)){
			RequestParam params = mp.getParameterAnnotation(RequestParam.class);
			if(pvalue==null && params.required() && (paramValue=params.defaultValue())==ValueConstants.DEFAULT_NONE){
				throw new BaseException("parameter["+params.name()+"] must be required : " + mp.getParameterName());
			}
			parameterNameAsPrefix = true;
		}else if(isUriVariables(mp) || mp.hasParameterAnnotation(FieldName.class)){
			parameterNameAsPrefix = true;
		}else if(beanToMapConvertor.isMappableValue(pvalue)){//可直接映射为值的参数
			parameterNameAsPrefix = true;
		}
		
		if(parameterNameAsPrefix){
			prefix = mp.getParameterName();
		}
		beanToMapConvertor.flatObject(prefix, paramValue, (k, v, ctx)->{
			values.add(k, v);
		});
		
		/*if(falatable){
//			beanToMapConvertor.flatObject(mp.getParameterName(), paramValue, (k, v, ctx)->{
			beanToMapConvertor.flatObject(mp.getParameterName(), paramValue, (k, v, ctx)->{
				if(v instanceof Enum){
					Enum<?> e = (Enum<?>)v;
					if(e instanceof ValueEnum){
						v = ((ValueEnum<?>)e).getValue();
					}else{//默认使用name
						v = e.name();
					}
				}else if(v instanceof Resource){
					//ignore,忽略,不转为string
				}else{
					v = v.toString();
				}
				if(ctx!=null){
//					System.out.println("ctx.getName():"+ctx.getName());
					values.add(ctx.getName(), v);
				}else{
					values.add(k, v);
				}
//				values.add(k, v);
			});
		}else{
			values.add(mp.getParameterName(), pvalue);
		}*/
	}
 
Example 12
@Override
protected String getDefaultValue(final RequestParam annotation) {
    return annotation.defaultValue();
}