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


Java Validator類代碼示例

本文整理匯總了Java中org.springframework.validation.Validator的典型用法代碼示例。如果您正苦於以下問題:Java Validator類的具體用法?Java Validator怎麽用?Java Validator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: customValidation

import org.springframework.validation.Validator; //導入依賴的package包/類
@Test
public void customValidation() throws Exception {
	DefaultMessageHandlerMethodFactory instance = createInstance();
	instance.setValidator(new Validator() {
		@Override
		public boolean supports(Class<?> clazz) {
			return String.class.isAssignableFrom(clazz);
		}
		@Override
		public void validate(Object target, Errors errors) {
			String value = (String) target;
			if ("failure".equals(value)) {
				errors.reject("not a valid value");
			}
		}
	});
	instance.afterPropertiesSet();

	InvocableHandlerMethod invocableHandlerMethod =
			createInvocableHandlerMethod(instance, "payloadValidation", String.class);
	thrown.expect(MethodArgumentNotValidException.class);
	invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:DefaultMessageHandlerMethodFactoryTests.java

示例2: SendController

import org.springframework.validation.Validator; //導入依賴的package包/類
@Autowired
public SendController(final MessageSenderService messageService,
                      final @Qualifier("mvcValidator") Validator validator,
                      final SecureTransferConfiguration config) {
    this.messageService = messageService;
    this.validator = validator;
    this.config = config;
}
 
開發者ID:osiegmar,項目名稱:setra,代碼行數:9,代碼來源:SendController.java

示例3: setValidators

import org.springframework.validation.Validator; //導入依賴的package包/類
/**
 * Registreer de specifieke validators.
 * @param validators validators
 */
public void setValidators(final Validator[] validators) {
    for (final Validator validator : validators) {
        if (!(validator instanceof GlobalValidator)) {
            this.validators.add(validator);
        }
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:WebConfiguratie.java

示例4: supports

import org.springframework.validation.Validator; //導入依賴的package包/類
@Override
public boolean supports(final Class<?> clazz) {
    for (final Validator validator : validators) {
        if (validator.supports(clazz)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:10,代碼來源:WebConfiguratie.java

示例5: validate

import org.springframework.validation.Validator; //導入依賴的package包/類
@Override
public void validate(final Object target, final Errors errors) {
    for (final Validator validator : validators) {
        if (validator.supports(target.getClass())) {
            validator.validate(target, errors);
        }
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:9,代碼來源:WebConfiguratie.java

示例6: validate

import org.springframework.validation.Validator; //導入依賴的package包/類
public void validate(Object target, Errors errors) {
    Set<ConstraintViolation<Object>> constraintViolations = beanValidator.validate(target);
    for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
        String propertyPath = constraintViolation.getPropertyPath().toString();
        String message = constraintViolation.getMessage();
        errors.rejectValue(propertyPath, "", message);
    }
    for(Validator validator: springValidators) {
        validator.validate(target, errors);
    }
}
 
開發者ID:TomirKlos,項目名稱:Webstore,代碼行數:12,代碼來源:ProductValidator.java

示例7: getValidator

import org.springframework.validation.Validator; //導入依賴的package包/類
@Override
public Validator getValidator() {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setValidationMessageSource(messageSource);

	return validator;
}
 
開發者ID:edylle,項目名稱:pathological-reports,代碼行數:8,代碼來源:PathologicalReportsApplication.java

示例8: getValidator

import org.springframework.validation.Validator; //導入依賴的package包/類
@Override
public Validator getValidator() {
    LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
    localValidatorFactoryBean.setProviderClass(org.hibernate.validator.HibernateValidator.class);
    localValidatorFactoryBean.setValidationMessageSource(messageSource());
    return localValidatorFactoryBean;
}
 
開發者ID:numsg,項目名稱:spring-boot-seed,代碼行數:8,代碼來源:WebConfig.java

示例9: supportedValidatorsFor

import org.springframework.validation.Validator; //導入依賴的package包/類
private Validator[] supportedValidatorsFor(Class<?> clazz) {
    final Set<Validator> supportedValidators = new HashSet<>();
    for (Validator validator : validators) {
        if (validator.supports(clazz)) {
            supportedValidators.add(validator);
        }
    }
    return supportedValidators.toArray(new Validator[supportedValidators.size()]);
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:10,代碼來源:CommonControllerAdvice.java

示例10: simpValidatorCustom

import org.springframework.validation.Validator; //導入依賴的package包/類
@Test
public void simpValidatorCustom() {
	final Validator validator = mock(Validator.class);
	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
		@Override
		public Validator getValidator() {
			return validator;
		}
	};

	assertSame(validator, config.simpValidator());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:13,代碼來源:MessageBrokerConfigurationTests.java

示例11: simpValidatorInjected

import org.springframework.validation.Validator; //導入依賴的package包/類
@Test
public void simpValidatorInjected() {
	SimpAnnotationMethodMessageHandler messageHandler =
			this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);

	assertThat(messageHandler.getValidator(), Matchers.notNullValue(Validator.class));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:8,代碼來源:MessageBrokerConfigurationTests.java

示例12: testValidator

import org.springframework.validation.Validator; //導入依賴的package包/類
private Validator testValidator() {
	return new Validator() {
		@Override
		public boolean supports(Class<?> clazz) {
			return String.class.isAssignableFrom(clazz);
		}
		@Override
		public void validate(Object target, Errors errors) {
			String value = (String) target;
			if ("invalidValue".equals(value)) {
				errors.reject("invalid value");
			}
		}
	};
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:PayloadArgumentResolverTests.java

示例13: bind

import org.springframework.validation.Validator; //導入依賴的package包/類
/**
 * Bind request parameters onto the given command bean
 * @param request request from which parameters will be bound
 * @param command command object, that must be a JavaBean
 * @throws Exception in case of invalid state or arguments
 */
protected void bind(HttpServletRequest request, Object command) throws Exception {
	logger.debug("Binding request parameters onto MultiActionController command");
	ServletRequestDataBinder binder = createBinder(request, command);
	binder.bind(request);
	if (this.validators != null) {
		for (Validator validator : this.validators) {
			if (validator.supports(command.getClass())) {
				ValidationUtils.invokeValidator(validator, command, binder.getBindingResult());
			}
		}
	}
	binder.closeNoCatch();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:MultiActionController.java

示例14: getValidator

import org.springframework.validation.Validator; //導入依賴的package包/類
@Override
public Validator getValidator() {
	List<Validator> candidates = new ArrayList<Validator>();
	for (WebMvcConfigurer configurer : this.delegates) {
		Validator validator = configurer.getValidator();
		if (validator != null) {
			candidates.add(validator);
		}
	}
	return selectSingleInstance(candidates, Validator.class);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:WebMvcConfigurerComposite.java

示例15: getValidator

import org.springframework.validation.Validator; //導入依賴的package包/類
@Override
public Validator getValidator() {
	return new Validator() {
		@Override
		public void validate(Object target, Errors errors) {
			errors.reject("invalid");
		}
		@Override
		public boolean supports(Class<?> clazz) {
			return true;
		}
	};
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:14,代碼來源:WebMvcConfigurationSupportExtensionTests.java


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