当前位置: 首页>>代码示例>>Java>>正文


Java WebDataBinderFactory.createBinder方法代码示例

本文整理汇总了Java中org.springframework.web.bind.support.WebDataBinderFactory.createBinder方法的典型用法代码示例。如果您正苦于以下问题:Java WebDataBinderFactory.createBinder方法的具体用法?Java WebDataBinderFactory.createBinder怎么用?Java WebDataBinderFactory.createBinder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.bind.support.WebDataBinderFactory的用法示例。


在下文中一共展示了WebDataBinderFactory.createBinder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAttributeFromRequestValue

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
/**
 * Create a model attribute from a String request value (e.g. URI template
 * variable, request parameter) using type conversion.
 * <p>The default implementation converts only if there a registered
 * {@link Converter} that can perform the conversion.
 * @param sourceValue the source value to create the model attribute from
 * @param attributeName the name of the attribute, never {@code null}
 * @param methodParam the method parameter
 * @param binderFactory for creating WebDataBinder instance
 * @param request the current request
 * @return the created model attribute, or {@code null}
 * @throws Exception
 */
protected Object createAttributeFromRequestValue(String sourceValue, String attributeName,
		MethodParameter methodParam, WebDataBinderFactory binderFactory, NativeWebRequest request)
		throws Exception {

	DataBinder binder = binderFactory.createBinder(request, null, attributeName);
	ConversionService conversionService = binder.getConversionService();
	if (conversionService != null) {
		TypeDescriptor source = TypeDescriptor.valueOf(String.class);
		TypeDescriptor target = new TypeDescriptor(methodParam);
		if (conversionService.canConvert(source, target)) {
			return binder.convertIfNecessary(sourceValue, methodParam.getParameterType(), methodParam);
		}
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:ServletModelAttributeMethodProcessor.java

示例2: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
/**
 * Throws MethodArgumentNotValidException if validation fails.
 * @throws HttpMessageNotReadableException if {@link RequestBody#required()}
 * is {@code true} and there is no body content or if there is no suitable
 * converter to read the content with.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	Object arg = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType());
	String name = Conventions.getVariableNameForParameter(parameter);

	WebDataBinder binder = binderFactory.createBinder(webRequest, arg, name);
	if (arg != null) {
		validateIfApplicable(binder, parameter);
		if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
			throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
		}
	}
	mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());

	return arg;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:RequestResponseBodyMethodProcessor.java

示例3: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的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

示例4: createAttributeFromRequestValue

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
protected Object createAttributeFromRequestValue(String sourceValue,
										 String attributeName,
										 MethodParameter parameter,
										 WebDataBinderFactory binderFactory,
										 NativeWebRequest request) throws Exception {
DataBinder binder = binderFactory.createBinder(request, null, attributeName);
ConversionService conversionService = binder.getConversionService();
if (conversionService != null) {
	TypeDescriptor source = TypeDescriptor.valueOf(String.class);
	TypeDescriptor target = new TypeDescriptor(parameter);
	if (conversionService.canConvert(source, target)) {
		return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
	}
}
	return null;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:17,代码来源:NamespaceModelAttributeMethodProcessor.java

示例5: createAttributeFromRequestValue

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
/**
 * Create a model attribute from a String request value (e.g. URI template
 * variable, request parameter) using type conversion.
 * <p>The default implementation converts only if there a registered
 * {@link org.springframework.core.convert.converter.Converter} that can perform the conversion.
 *
 * @param sourceValue   the source value to create the model attribute from
 * @param attributeName the name of the attribute, never {@code null}
 * @param parameter     the method parameter
 * @param binderFactory for creating WebDataBinder instance
 * @param request       the current request
 * @return the created model attribute, or {@code null}
 * @throws Exception
 */
protected Object createAttributeFromRequestValue(String sourceValue,
                                                 String attributeName,
                                                 MethodParameter parameter,
                                                 WebDataBinderFactory binderFactory,
                                                 NativeWebRequest request) throws Exception {
    DataBinder binder = binderFactory.createBinder(request, null, attributeName);
    ConversionService conversionService = binder.getConversionService();
    if (conversionService != null) {
        TypeDescriptor source = TypeDescriptor.valueOf(String.class);
        TypeDescriptor target = new TypeDescriptor(parameter);
        if (conversionService.canConvert(source, target)) {
            return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
        }
    }
    return null;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:31,代码来源:FormModelMethodArgumentResolver.java

示例6: createAttributeFromRequestValue

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
/**
 * Create a model attribute from a String request value (e.g. URI template
 * variable, request parameter) using type conversion.
 * <p>The default implementation converts only if there a registered 
 * {@link Converter} that can perform the conversion.
 * @param sourceValue the source value to create the model attribute from
 * @param attributeName the name of the attribute, never {@code null}
 * @param parameter the method parameter
 * @param binderFactory for creating WebDataBinder instance
 * @param request the current request
 * @return the created model attribute, or {@code null}
 * @throws Exception
 */
protected Object createAttributeFromRequestValue(String sourceValue,
                                             String attributeName, 
                                             MethodParameter parameter, 
                                             WebDataBinderFactory binderFactory, 
                                             NativeWebRequest request) throws Exception {
    DataBinder binder = binderFactory.createBinder(request, null, attributeName);
    ConversionService conversionService = binder.getConversionService();
    if (conversionService != null) {
        TypeDescriptor source = TypeDescriptor.valueOf(String.class);
        TypeDescriptor target = new TypeDescriptor(parameter);
        if (conversionService.canConvert(source, target)) {
            return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
        }
    }
    return null;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:30,代码来源:FormModelMethodArgumentResolver.java

示例7: createAttributeFromRequestValue

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
/**
 * Create a model attribute from a String request value (e.g. URI template
 * variable, request parameter) using type conversion.
 * <p>The default implementation converts only if there a registered
 * {@link Converter} that can perform the conversion.
 * @param sourceValue the source value to create the model attribute from
 * @param attributeName the name of the attribute, never {@code null}
 * @param parameter the method parameter
 * @param binderFactory for creating WebDataBinder instance
 * @param request the current request
 * @return the created model attribute, or {@code null}
 * @throws Exception
 */
protected Object createAttributeFromRequestValue(String sourceValue,
											 String attributeName,
											 MethodParameter parameter,
											 WebDataBinderFactory binderFactory,
											 NativeWebRequest request) throws Exception {
	DataBinder binder = binderFactory.createBinder(request, null, attributeName);
	ConversionService conversionService = binder.getConversionService();
	if (conversionService != null) {
		TypeDescriptor source = TypeDescriptor.valueOf(String.class);
		TypeDescriptor target = new TypeDescriptor(parameter);
		if (conversionService.canConvert(source, target)) {
			return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
		}
	}
	return null;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:30,代码来源:ServletModelAttributeMethodProcessor.java

示例8: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * @throws MethodArgumentNotValidException if validation fails
 * @throws HttpMessageNotReadableException if {@link RequestBody#required()}
 * 	is {@code true} and there is no body content or if there is no suitable
 * 	converter to read the content with.
 */
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	Object argument = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType());

	String name = Conventions.getVariableNameForParameter(parameter);
	WebDataBinder binder = binderFactory.createBinder(webRequest, argument, name);

	if (argument != null) {
		validate(binder, parameter);
	}

	mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());

	return argument;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:RequestResponseBodyMethodProcessor.java

示例9: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的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 request, WebDataBinderFactory binderFactory)
		throws Exception {

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

	WebDataBinder binder = binderFactory.createBinder(request, attribute, name);
	if (binder.getTarget() != null) {
		bindRequestParameters(binder, request);
		validateIfApplicable(binder, parameter);
		if (binder.getBindingResult().hasErrors()) {
			if (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.getTarget();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:ModelAttributeMethodProcessor.java

示例10: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的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

示例11: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
	ModelMap redirectAttributes  = new RedirectAttributesModelMap(dataBinder);
	mavContainer.setRedirectModel(redirectAttributes);
	return redirectAttributes;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:RedirectAttributesMethodArgumentResolver.java

示例12: createBinder

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
@Test
public void createBinder() throws Exception {
	WebDataBinderFactory factory = createBinderFactory("initBinder", WebDataBinder.class);
	WebDataBinder dataBinder = factory.createBinder(webRequest, null, null);

	assertNotNull(dataBinder.getDisallowedFields());
	assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:InitBinderDataBinderFactoryTests.java

示例13: createBinderWithGlobalInitialization

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
@Test
public void createBinderWithGlobalInitialization() throws Exception {
	ConversionService conversionService = new DefaultFormattingConversionService();
	bindingInitializer.setConversionService(conversionService);

	WebDataBinderFactory factory = createBinderFactory("initBinder", WebDataBinder.class);
	WebDataBinder dataBinder = factory.createBinder(webRequest, null, null);

	assertSame(conversionService, dataBinder.getConversionService());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:InitBinderDataBinderFactoryTests.java

示例14: createBinderWithAttrName

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
@Test
public void createBinderWithAttrName() throws Exception {
	WebDataBinderFactory factory = createBinderFactory("initBinderWithAttributeName", WebDataBinder.class);
	WebDataBinder dataBinder = factory.createBinder(webRequest, null, "foo");

	assertNotNull(dataBinder.getDisallowedFields());
	assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:InitBinderDataBinderFactoryTests.java

示例15: createBinderWithAttrNameNoMatch

import org.springframework.web.bind.support.WebDataBinderFactory; //导入方法依赖的package包/类
@Test
public void createBinderWithAttrNameNoMatch() throws Exception {
	WebDataBinderFactory factory = createBinderFactory("initBinderWithAttributeName", WebDataBinder.class);
	WebDataBinder dataBinder = factory.createBinder(webRequest, null, "invalidName");

	assertNull(dataBinder.getDisallowedFields());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:InitBinderDataBinderFactoryTests.java


注:本文中的org.springframework.web.bind.support.WebDataBinderFactory.createBinder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。