Java Code Examples for org.springframework.web.context.request.NativeWebRequest#getParameter()

The following examples show how to use org.springframework.web.context.request.NativeWebRequest#getParameter() . 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
Source File: RequestJsonToPoHandlerMethodArgumentResolver.java    From jframework with Apache License 2.0 6 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory binderFactory) throws Exception {
    RequestJsonToPo parameterAnnotation = parameter.getParameterAnnotation(RequestJsonToPo.class);
    Objects.requireNonNull(parameterAnnotation);
    String value = parameterAnnotation.value();
    Class<?> clazz = parameter.getNestedParameterType();
    String jsonParameter = nativeWebRequest.getParameter(value);
    if (jsonParameter == null) {
        if (clazz.isAssignableFrom(List.class)) {
            return Lists.newArrayList();
        }
        return clazz.newInstance();
    }
    jsonParameter = URLDecoder.decode(jsonParameter, StandardCharsets.UTF_8.name());

    if (clazz.isAssignableFrom(List.class) || clazz.isAssignableFrom(ArrayList.class)) {
        String typeName = ((sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) parameter.getGenericParameterType()).getActualTypeArguments()[0].getTypeName();
        Class<?> aClass = Class.forName(typeName);
        return JsonUtil.toList(jsonParameter, aClass);
    } else {
        return JsonUtil.toObject(jsonParameter, clazz);
    }
}
 
Example 2
Source File: EntityModelAttributeMethodProcessor.java    From java-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiate the model attribute from a URI template variable or from a
 * request parameter if the name matches to the model attribute name and if
 * there is an appropriate type conversion strategy. If none of these are
 * true delegate back to the base class.
 * 
 * @see #createAttributeFromRequestValue
 */
@Override
protected final Object createAttribute(String attributeName, MethodParameter methodParam,
		WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception {

	String value = getRequestValueForAttribute(attributeName, request);
	if (value != null) {
		Object attribute = createAttributeFromRequestValue(value, attributeName, methodParam, binderFactory,
				request);
		if (attribute != null) {
			return attribute;
		}
	} else {
		Class<?> parameterType = methodParam.getParameterType();
		if (ClassUtils.isAssignable(BaseEntity.class, parameterType)) {
			String id = request.getParameter("id");
			if (!Strings.isNullOrEmpty(id)) {
				return conversionService.convert(id, methodParam.getParameterType());
			} else {
				return entityService.getService(parameterType).newEntity();
			}
		}
	}

	return super.createAttribute(attributeName, methodParam, binderFactory, request);
}
 
Example 3
Source File: GlobalSearchHandlerMethodArgumentResolver.java    From springlets with Apache License 2.0 6 votes vote down vote up
@Override
public GlobalSearch resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
    NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {

  String searchValue = webRequest.getParameter(getSearchValueParameter());
  if (StringUtils.isEmpty(searchValue)) {
    return null;
  }
  String regexp = webRequest.getParameter(getRegexpParameter());
  if ("true".equalsIgnoreCase(regexp)) {
    return new GlobalSearch(searchValue, true);
  } else if ("false".equalsIgnoreCase(regexp)) {
    return new GlobalSearch(searchValue, false);
  }

  return new GlobalSearch(searchValue);
}
 
Example 4
Source File: ServletModelAttributeMethodProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the
 * model attribute through type conversion from String to the target type.
 * <p>The default implementation looks for the attribute name to match
 * a URI variable first and then a request parameter.
 * @param attributeName the model attribute name
 * @param request the current request
 * @return the request value to try to convert, or {@code null} if none
 */
@Nullable
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
	Map<String, String> variables = getUriTemplateVariables(request);
	String variableValue = variables.get(attributeName);
	if (StringUtils.hasText(variableValue)) {
		return variableValue;
	}
	String parameterValue = request.getParameter(attributeName);
	if (StringUtils.hasText(parameterValue)) {
		return parameterValue;
	}
	return null;
}
 
Example 5
Source File: ServletModelAttributeMethodProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the
 * model attribute through type conversion from String to the target type.
 * <p>The default implementation looks for the attribute name to match
 * a URI variable first and then a request parameter.
 * @param attributeName the model attribute name
 * @param request the current request
 * @return the request value to try to convert, or {@code null} if none
 */
@Nullable
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
	Map<String, String> variables = getUriTemplateVariables(request);
	String variableValue = variables.get(attributeName);
	if (StringUtils.hasText(variableValue)) {
		return variableValue;
	}
	String parameterValue = request.getParameter(attributeName);
	if (StringUtils.hasText(parameterValue)) {
		return parameterValue;
	}
	return null;
}
 
Example 6
Source File: FormModelMethodArgumentResolver.java    From distributed-transaction-process with MIT License 5 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the
 * model attribute through type conversion from String to the target type.
 * <p>The default implementation looks for the attribute name to match
 * a URI variable first and then a request parameter.
 *
 * @param attributeName the model attribute name
 * @param request       the current request
 * @return the request value to try to convert or {@code null}
 */
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
    Map<String, String> variables = getUriTemplateVariables(request);
    if (StringUtils.hasText(variables.get(attributeName))) {
        return variables.get(attributeName);
    } else if (StringUtils.hasText(request.getParameter(attributeName))) {
        return request.getParameter(attributeName);
    } else {
        return null;
    }
}
 
Example 7
Source File: ServletModelAttributeMethodProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the
 * model attribute through type conversion from String to the target type.
 * <p>The default implementation looks for the attribute name to match
 * a URI variable first and then a request parameter.
 * @param attributeName the model attribute name
 * @param request the current request
 * @return the request value to try to convert, or {@code null} if none
 */
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
	Map<String, String> variables = getUriTemplateVariables(request);
	String variableValue = variables.get(attributeName);
	if (StringUtils.hasText(variableValue)) {
		return variableValue;
	}
	String parameterValue = request.getParameter(attributeName);
	if (StringUtils.hasText(parameterValue)) {
		return parameterValue;
	}
	return null;
}
 
Example 8
Source File: JsonParamResolver.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    JsonParam jsonParam = parameter.getParameterAnnotation(JsonParam.class);
    String object = webRequest.getParameter(jsonParam.value());
    if (null != object) {
        Class type = jsonParam.type() != Void.class ? jsonParam.type() : parameter.getParameterType();
        return fastJsonHttpMessageConverter.readByString(type, object);
    }
    return null;
}
 
Example 9
Source File: ServletModelAttributeMethodProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the
 * model attribute through type conversion from String to the target type.
 * <p>The default implementation looks for the attribute name to match
 * a URI variable first and then a request parameter.
 * @param attributeName the model attribute name
 * @param request the current request
 * @return the request value to try to convert or {@code null}
 */
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
	Map<String, String> variables = getUriTemplateVariables(request);
	if (StringUtils.hasText(variables.get(attributeName))) {
		return variables.get(attributeName);
	}
	else if (StringUtils.hasText(request.getParameter(attributeName))) {
		return request.getParameter(attributeName);
	}
	else {
		return null;
	}
}
 
Example 10
Source File: FormModelMethodArgumentResolver.java    From es with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the
 * model attribute through type conversion from String to the target type.
 * <p>The default implementation looks for the attribute name to match
 * a URI variable first and then a request parameter.
 *
 * @param attributeName the model attribute name
 * @param request       the current request
 * @return the request value to try to convert or {@code null}
 */
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
    Map<String, String> variables = getUriTemplateVariables(request);
    if (StringUtils.hasText(variables.get(attributeName))) {
        return variables.get(attributeName);
    } else if (StringUtils.hasText(request.getParameter(attributeName))) {
        return request.getParameter(attributeName);
    } else {
        return null;
    }
}
 
Example 11
Source File: ParameterContentNegotiationStrategy.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@Nullable
protected String getMediaTypeKey(NativeWebRequest request) {
	return request.getParameter(getParameterName());
}
 
Example 12
Source File: ParameterContentNegotiationStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Nullable
protected String getMediaTypeKey(NativeWebRequest request) {
	return request.getParameter(getParameterName());
}
 
Example 13
Source File: ParameterContentNegotiationStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected String getMediaTypeKey(NativeWebRequest request) {
	return request.getParameter(getParameterName());
}
 
Example 14
Source File: ParameterContentNegotiationStrategy.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected String getMediaTypeKey(NativeWebRequest request) {
	return request.getParameter(getParameterName());
}
 
Example 15
Source File: EntityModelAttributeMethodProcessor.java    From java-platform with Apache License 2.0 3 votes vote down vote up
/**
 * Obtain a value from the request that may be used to instantiate the model
 * attribute through type conversion from String to the target type.
 * <p>
 * The default implementation looks for the attribute name to match a URI
 * variable first and then a request parameter.
 * 
 * @param attributeName
 *            the model attribute name
 * @param request
 *            the current request
 * @return the request value to try to convert or {@code null}
 */
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) {
	Map<String, String> variables = getUriTemplateVariables(request);
	if (StringUtils.hasText(variables.get(attributeName))) {
		return variables.get(attributeName);
	} else if (StringUtils.hasText(request.getParameter(attributeName))) {
		return request.getParameter(attributeName);
	} else {
		return null;
	}
}