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


Java WebDataBinder.convertIfNecessary方法代碼示例

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


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

示例1: resolveCookieValue

import org.springframework.web.bind.WebDataBinder; //導入方法依賴的package包/類
private Object resolveCookieValue(String cookieName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (cookieName.length() == 0) {
		cookieName = getRequiredParameterName(methodParam);
	}
	Object cookieValue = resolveCookieValue(cookieName, paramType, webRequest);
	if (cookieValue == null) {
		if (defaultValue != null) {
			cookieValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingCookieException(cookieName, paramType);
		}
		cookieValue = checkValue(cookieName, cookieValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, cookieName);
	initBinder(handlerForInitBinderCall, cookieName, binder, webRequest);
	return binder.convertIfNecessary(cookieValue, paramType, methodParam);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:HandlerMethodInvoker.java

示例2: resolveArgument

import org.springframework.web.bind.WebDataBinder; //導入方法依賴的package包/類
/**
 * Resolve the argument from the model or if not found instantiate it with
 * its default if it is available. The model attribute is then populated
 * with request values via data binding and optionally validated
 * if {@code @java.validation.Valid} is present on the argument.
 * @throws BindException if data binding and validation result in an error
 * and the next method parameter is not of type {@link Errors}.
 * @throws Exception if WebDataBinder initialization fails.
 */
@Override
public final Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	String name = ModelFactory.getNameForParameter(parameter);
	Object attribute = (mavContainer.containsAttribute(name) ?
			mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, webRequest));

	WebDataBinder binder = binderFactory.createBinder(webRequest, attribute, name);
	if (binder.getTarget() != null) {
		bindRequestParameters(binder, webRequest);
		validateIfApplicable(binder, parameter);
		if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
			throw new BindException(binder.getBindingResult());
		}
	}

	// Add resolved attribute and BindingResult at the end of the model
	Map<String, Object> bindingResultModel = binder.getBindingResult().getModel();
	mavContainer.removeAttributes(bindingResultModel);
	mavContainer.addAllAttributes(bindingResultModel);

	return binder.convertIfNecessary(binder.getTarget(), parameter.getParameterType(), parameter);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:ModelAttributeMethodProcessor.java

示例3: resolveArgument

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

	Class<?> paramType = parameter.getParameterType();
	NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);

	Object arg = resolveName(namedValueInfo.name, parameter, webRequest);
	if (arg == null) {
		if (namedValueInfo.defaultValue != null) {
			arg = resolveDefaultValue(namedValueInfo.defaultValue);
		}
		else if (namedValueInfo.required) {
			handleMissingValue(namedValueInfo.name, parameter);
		}
		arg = handleNullValue(namedValueInfo.name, arg, paramType);
	}
	else if ("".equals(arg) && (namedValueInfo.defaultValue != null)) {
		arg = resolveDefaultValue(namedValueInfo.defaultValue);
	}

	if (binderFactory != null) {
		WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
		arg = binder.convertIfNecessary(arg, paramType, parameter);
	}

	handleResolvedValue(arg, namedValueInfo.name, parameter, mavContainer, webRequest);

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

示例4: resolveRequestParam

import org.springframework.web.bind.WebDataBinder; //導入方法依賴的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

示例5: resolveRequestHeader

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

	Class<?> paramType = methodParam.getParameterType();
	if (Map.class.isAssignableFrom(paramType)) {
		return resolveRequestHeaderMap((Class<? extends Map<?, ?>>) paramType, webRequest);
	}
	if (headerName.length() == 0) {
		headerName = getRequiredParameterName(methodParam);
	}
	Object headerValue = null;
	String[] headerValues = webRequest.getHeaderValues(headerName);
	if (headerValues != null) {
		headerValue = (headerValues.length == 1 ? headerValues[0] : headerValues);
	}
	if (headerValue == null) {
		if (defaultValue != null) {
			headerValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingHeaderException(headerName, paramType);
		}
		headerValue = checkValue(headerName, headerValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, headerName);
	initBinder(handlerForInitBinderCall, headerName, binder, webRequest);
	return binder.convertIfNecessary(headerValue, paramType, methodParam);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:HandlerMethodInvoker.java

示例6: resolvePathVariable

import org.springframework.web.bind.WebDataBinder; //導入方法依賴的package包/類
private Object resolvePathVariable(String pathVarName, MethodParameter methodParam,
		NativeWebRequest webRequest, Object handlerForInitBinderCall) throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (pathVarName.length() == 0) {
		pathVarName = getRequiredParameterName(methodParam);
	}
	String pathVarValue = resolvePathVariable(pathVarName, paramType, webRequest);
	WebDataBinder binder = createBinder(webRequest, null, pathVarName);
	initBinder(handlerForInitBinderCall, pathVarName, binder, webRequest);
	return binder.convertIfNecessary(pathVarValue, paramType, methodParam);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:13,代碼來源:HandlerMethodInvoker.java

示例7: resolveArgument

import org.springframework.web.bind.WebDataBinder; //導入方法依賴的package包/類
/**
 * Resolve the argument from the model or if not found instantiate it with
 * its default if it is available. The model attribute is then populated
 * with request values via data binding and optionally validated
 * if {@code @java.validation.Valid} is present on the argument.
 *
 * @throws org.springframework.validation.BindException
 *                   if data binding and validation result in an error
 *                   and the next method parameter is not of type {@link org.springframework.validation.Errors}.
 * @throws Exception if WebDataBinder initialization fails.
 */
public final Object resolveArgument(MethodParameter parameter,
                                    ModelAndViewContainer mavContainer,
                                    NativeWebRequest request,
                                    WebDataBinderFactory binderFactory) throws Exception {
    String name = parameter.getParameterAnnotation(FormModel.class).value();

    Object target = (mavContainer.containsAttribute(name)) ?
            mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);

    WebDataBinder binder = binderFactory.createBinder(request, target, name);
    target = binder.getTarget();
    if (target != null) {
        bindRequestParameters(mavContainer, binderFactory, binder, request, parameter);

        validateIfApplicable(binder, parameter);
        if (binder.getBindingResult().hasErrors()) {
            if (isBindExceptionRequired(binder, parameter)) {
                throw new BindException(binder.getBindingResult());
            }
        }
    }

    target = binder.convertIfNecessary(binder.getTarget(), parameter.getParameterType());
    mavContainer.addAttribute(name, target);

    return target;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:39,代碼來源:FormModelMethodArgumentResolver.java

示例8: resolveArgument

import org.springframework.web.bind.WebDataBinder; //導入方法依賴的package包/類
/**
 * Resolve the argument from the model or if not found instantiate it with 
 * its default if it is available. The model attribute is then populated 
 * with request values via data binding and optionally validated
 * if {@code @java.validation.Valid} is present on the argument.
 * @throws BindException if data binding and validation result in an error
 * and the next method parameter is not of type {@link Errors}.
 * @throws Exception if WebDataBinder initialization fails.
 */
public final Object resolveArgument(MethodParameter parameter,
                                    ModelAndViewContainer mavContainer,
                                    NativeWebRequest request,
                                    WebDataBinderFactory binderFactory) throws Exception {
    String name = parameter.getParameterAnnotation(FormModel.class).value();
    
    Object target = (mavContainer.containsAttribute(name)) ?
            mavContainer.getModel().get(name) : createAttribute(name, parameter, binderFactory, request);
    
    WebDataBinder binder = binderFactory.createBinder(request, target, name);
    target = binder.getTarget();
    if (target != null) {
        bindRequestParameters(mavContainer, binderFactory, binder, request, parameter);
        
        validateIfApplicable(binder, parameter);
        if (binder.getBindingResult().hasErrors()) {
            if (isBindExceptionRequired(binder, parameter)) {
                throw new BindException(binder.getBindingResult());
            }
        }
    }
    
    target = binder.convertIfNecessary(binder.getTarget(), parameter.getParameterType());
    mavContainer.addAttribute(name, target);
    
    return target;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:37,代碼來源:FormModelMethodArgumentResolver.java


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