當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。