当前位置: 首页>>代码示例>>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;未经允许,请勿转载。