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


Java WebDataBinderFactory类代码示例

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


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

示例1: resolveArgument

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

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

    ExcelRequestBody annotation = parameter.getParameterAnnotation(ExcelRequestBody.class);
    if (multipartRequest != null) {
        List<Object> result = new ArrayList<>();
        List<MultipartFile> files = multipartRequest.getFiles(annotation.name());
        for (MultipartFile file : files) {
            if (converters.supportsExcelType(annotation.type())) {
                List<?> part = converters.fromExcel(annotation, file.getInputStream());
                result.addAll(part);
            }
        }
        return result;
    }
    return null;

}
 
开发者ID:natsuforyou,项目名称:spring-boot-excel-plugin,代码行数:22,代码来源:ExcelRequestResponseBodyHandler.java

示例2: resolveArgument

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

    if (!isBase64(nonceBase64)) {
        throw new BadRequestException("Nonce must be base64");
    }
    if (!isBase64(nonceSignatureBase64)) {
        throw new BadRequestException("Nonce signature must be base64");
    }

    return NonceAuthenticationImpl.builder()
            .nonceBase64(nonceBase64)
            .nonceSignatureBase64(nonceSignatureBase64)
            .build();
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:18,代码来源:NonceAuthenticationArgumentResolver.java

示例3: resolveArgument

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

	ModelMap model = mavContainer.getModel();
	if (model.size() > 0) {
		int lastIndex = model.size()-1;
		String lastKey = new ArrayList<String>(model.keySet()).get(lastIndex);
		if (lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
			return model.get(lastKey);
		}
	}

	throw new IllegalStateException(
			"An Errors/BindingResult argument is expected to be declared immediately after the model attribute, " +
			"the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:ErrorsMethodArgumentResolver.java

示例4: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
/**
 * Delegate to the {@link WebArgumentResolver} instance.
 * @exception IllegalStateException if the resolved value is not assignable
 * to the method parameter.
 */
@Override
public Object resolveArgument(
		MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
		throws Exception {

	Class<?> paramType = parameter.getParameterType();
	Object result = this.adaptee.resolveArgument(parameter, webRequest);
	if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
		throw new IllegalStateException(
				"Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
				"resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
				"]. Consider declaring the argument type in a less specific fashion.");
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AbstractWebArgumentResolverAdapter.java

示例5: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);

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

    if (paramType.equals(WebInput.class)) {
        return new WebInput(request);
    } else if (paramType.equals(WebOutput.class)) {
        return new WebOutput(response);
    } else if (paramType.equals(FileWebInput.class)) {
        return new FileWebInput(request);
    }

    return null;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:18,代码来源:WebResourceDataHandlerMethodArgumentResolver.java

示例6: createAttribute

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
/**
 * 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;
		}
	}

	return super.createAttribute(attributeName, methodParam, binderFactory, request);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ServletModelAttributeMethodProcessor.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 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

示例8: resolveArgument

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

	ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
	Type paramType = getHttpEntityType(parameter);

	Object body = readWithMessageConverters(webRequest, parameter, paramType);
	if (RequestEntity.class == parameter.getParameterType()) {
		return new RequestEntity<Object>(body, inputMessage.getHeaders(),
				inputMessage.getMethod(), inputMessage.getURI());
	}
	else {
		return new HttpEntity<Object>(body, inputMessage.getHeaders());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:HttpEntityMethodProcessor.java

示例9: resolveArgument

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
/**
 * Return a Map with all URI template variables or an empty map.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, String> uriTemplateVars =
			(Map<String, String>) webRequest.getAttribute(
					HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (!CollectionUtils.isEmpty(uriTemplateVars)) {
		return new LinkedHashMap<String, String>(uriTemplateVars);
	}
	else {
		return Collections.emptyMap();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:PathVariableMapMethodArgumentResolver.java

示例10: 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

示例11: resolveArgument

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

	ModelMap model = mavContainer.getModel();
	if (model.size() > 0) {
		int lastIndex = model.size()-1;
		String lastKey = new ArrayList<String>(model.keySet()).get(lastIndex);
		if (lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
			return model.get(lastKey);
		}
	}

	throw new IllegalStateException(
			"An Errors/BindingResult argument is expected to be declared immediately after the model attribute, " +
			"the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ErrorsMethodArgumentResolver.java

示例12: 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

示例13: resolveArgumentOrdering

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
@Test  // SPR-9378
public void resolveArgumentOrdering() throws Exception {
	String name = "testBean";
	Object testBean = new TestBean(name);
	mavContainer.addAttribute(name, testBean);
	mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, testBean);

	Object anotherTestBean = new TestBean();
	mavContainer.addAttribute("anotherTestBean", anotherTestBean);

	StubRequestDataBinder dataBinder = new StubRequestDataBinder(testBean, name);
	WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
	given(binderFactory.createBinder(webRequest, testBean, name)).willReturn(dataBinder);

	processor.resolveArgument(paramModelAttr, mavContainer, webRequest, binderFactory);

	assertSame("Resolved attribute should be updated to be last in the order",
			testBean, mavContainer.getModel().values().toArray()[1]);
	assertSame("BindingResult of resolved attribute should be last in the order",
			dataBinder.getBindingResult(), mavContainer.getModel().values().toArray()[2]);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ModelAttributeMethodProcessorTests.java

示例14: resolveOptional

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void resolveOptional() throws Exception {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());
	WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

	Object result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(Optional.empty(), result);

	this.request.addParameter("name", "123");
	result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(123, ((Optional) result).get());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:RequestParamMethodArgumentResolverTests.java

示例15: updateModelBindingResult

import org.springframework.web.bind.support.WebDataBinderFactory; //导入依赖的package包/类
@Test
public void updateModelBindingResult() throws Exception {
	String commandName = "attr1";
	Object command = new Object();
	ModelAndViewContainer container = new ModelAndViewContainer();
	container.addAttribute(commandName, command);

	WebDataBinder dataBinder = new WebDataBinder(command, commandName);
	WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
	given(binderFactory.createBinder(this.webRequest, command, commandName)).willReturn(dataBinder);

	ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.sessionAttrsHandler);
	modelFactory.updateModel(this.webRequest, container);

	assertEquals(command, container.getModel().get(commandName));
	assertSame(dataBinder.getBindingResult(), container.getModel().get(bindingResultKey(commandName)));
	assertEquals(2, container.getModel().size());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ModelFactoryTests.java


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