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


Java NativeWebRequest.getParameterValues方法代碼示例

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


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

示例1: resolveName

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
	Object arg;

	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	MultipartHttpServletRequest multipartRequest =
		WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);

	if (MultipartFile.class.equals(parameter.getParameterType())) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFile(name);
	}
	else if (isMultipartFileCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name);
	}
	else if(isMultipartFileArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name).toArray(new MultipartFile[0]);
	}
	else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
		assertIsMultipartRequest(servletRequest);
		arg = servletRequest.getPart(name);
	}
	else if (isPartCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = new ArrayList<Object>(servletRequest.getParts());
	}
	else if (isPartArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = RequestPartResolver.resolvePart(servletRequest);
	}
	else {
		arg = null;
		if (multipartRequest != null) {
			List<MultipartFile> files = multipartRequest.getFiles(name);
			if (!files.isEmpty()) {
				arg = (files.size() == 1 ? files.get(0) : files);
			}
		}
		if (arg == null) {
			String[] paramValues = webRequest.getParameterValues(name);
			if (paramValues != null) {
				arg = paramValues.length == 1 ? paramValues[0] : paramValues;
			}
		}
	}

	return arg;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:54,代碼來源:RequestParamMethodArgumentResolver.java

示例2: resolveRequestParam

import org.springframework.web.context.request.NativeWebRequest; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Object resolveRequestParam(String paramName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) {
		return resolveRequestParamMap((Class<? extends Map<?, ?>>) paramType, webRequest);
	}
	if (paramName.length() == 0) {
		paramName = getRequiredParameterName(methodParam);
	}
	Object paramValue = null;
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		List<MultipartFile> files = multipartRequest.getFiles(paramName);
		if (!files.isEmpty()) {
			paramValue = (files.size() == 1 ? files.get(0) : files);
		}
	}
	if (paramValue == null) {
		String[] paramValues = webRequest.getParameterValues(paramName);
		if (paramValues != null) {
			paramValue = (paramValues.length == 1 ? paramValues[0] : paramValues);
		}
	}
	if (paramValue == null) {
		if (defaultValue != null) {
			paramValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingParameterException(paramName, paramType);
		}
		paramValue = checkValue(paramName, paramValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, paramName);
	initBinder(handlerForInitBinderCall, paramName, binder, webRequest);
	return binder.convertIfNecessary(paramValue, paramType, methodParam);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:HandlerMethodInvoker.java


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