本文整理汇总了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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例7: getValidator
import org.springframework.validation.Validator; //导入依赖的package包/类
@Override
public Validator getValidator() {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setValidationMessageSource(messageSource);
return validator;
}
示例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;
}
示例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()]);
}
示例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());
}
示例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));
}
示例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");
}
}
};
}
示例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();
}
示例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);
}
示例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