本文整理匯總了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