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


Java HibernateValidator類代碼示例

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


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

示例1: testSimpleValidationWithCustomProvider

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();
	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ValidatorFactoryTests.java

示例2: testSimpleValidationWithCustomProvider

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Test
public void testSimpleValidationWithCustomProvider() throws Exception {
	LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
	validator.setProviderClass(HibernateValidator.class);
	validator.afterPropertiesSet();

	ValidPerson person = new ValidPerson();
	Set<ConstraintViolation<ValidPerson>> result = validator.validate(person);
	assertEquals(2, result.size());
	for (ConstraintViolation<ValidPerson> cv : result) {
		String path = cv.getPropertyPath().toString();
		if ("name".equals(path) || "address.street".equals(path)) {
			assertTrue(cv.getConstraintDescriptor().getAnnotation() instanceof NotNull);
		}
		else {
			fail("Invalid constraint violation with path '" + path + "'");
		}
	}
	validator.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ValidatorFactoryTests.java

示例3: getConfiguration

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public RestlerConfig getConfiguration()  {
    ObjectMapper objectMapper = Jackson.newObjectMapper();

    ValidatorFactory validatorFactory = Validation
            .byProvider(HibernateValidator.class)
            .configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();


    final ConfigurationFactory<RestlerConfig> configurationFactory =
            new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw");

    try {
        return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE);
    } catch (Exception e) {
        throw new RuntimeException("Cannot get test configuration", e);
    }
}
 
開發者ID:researchgate,項目名稱:restler,代碼行數:21,代碼來源:TestRestlerModule.java

示例4: start

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class)
            .configure();
    configuration.parameterNameProvider(new ReflectionParameterNameProvider());
    configuration.messageInterpolator(new LocaleSpecificMessageInterpolator(configuration
            .getDefaultMessageInterpolator()));
    validatorFactory = configuration.buildValidatorFactory();
    Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_VENDOR, "AdeptJ");
    props.put(Constants.SERVICE_DESCRIPTION, "AdeptJ ValidatorService");
    servRegValidatorService = context.registerService(ValidatorService.class,
            new OSGiBeanValidatorService(this.validatorFactory.getValidator(),
                    configuration.getBootstrapConfiguration()),
            props);
}
 
開發者ID:AdeptJ,項目名稱:adeptj-modules,代碼行數:17,代碼來源:BeanValidationActivator.java

示例5: invoke

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
public Object invoke(final MethodInvocation mi) throws Throwable {
  checkNotNull(methodValidator);

  final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(HibernateValidator.class.getClassLoader());
    final Validate validate = mi.getMethod().getAnnotation(Validate.class);

    validateParameters(mi.getThis(), mi.getMethod(), mi.getArguments(), validate.groups());

    final Object result = mi.proceed();

    validateReturnValue(mi.getThis(), mi.getMethod(), result, validate.groups());

    return result;
  }
  finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:21,代碼來源:ValidationInterceptor.java

示例6: createConfiguration

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
/**
 * create hibernate validation configuration
 * 
 * @return
 */
protected HibernateValidatorConfiguration createConfiguration() {
	HibernateValidatorConfiguration configuration = null;
	if (this.isIgnoreClassHierarchy()) {
		ValidationProviderResolver resolver = new ValidationProviderResolver() {
			/**
			 * (non-Javadoc)
			 * 
			 * @see javax.validation.ValidationProviderResolver#getValidationProviders()
			 */
			@Override
			public List<ValidationProvider<?>> getValidationProviders() {
				List<ValidationProvider<?>> providers = new ArrayList<ValidationProvider<?>>(1);
				providers.add(new HibernateValidator513());
				return providers;
			}
		};
		configuration = Validation.byProvider(HibernateValidator513.class).providerResolver(resolver).configure();
	} else {
		configuration = Validation.byProvider(HibernateValidator.class).configure();
	}
	configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(
			MESSAGES)));
	return configuration;
}
 
開發者ID:bradwoo8621,項目名稱:nest-old,代碼行數:30,代碼來源:HibernateValidationConfigurationInitializer.java

示例7: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRole.class)
            .property("roleName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .constraint(new PatternDef().regexp("^(?!root$).+$").message(
                    "may not be root"))
            .property("roleCode", ElementType.FIELD)
            .constraint(new NotNullDef()).constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:20,代碼來源:SysRoleValidator.java

示例8: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRoute.class)
            .property("routeId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("name", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("url", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:22,代碼來源:SysRouteUpdateValidator.java

示例9: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysMenu.class)
            .property("menuName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .property("menuPath", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"))
            .property("parentId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("icon", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:25,代碼來源:SysMenuValidator.java

示例10: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysUser.class)
            .property("userId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("username", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(3))
            .constraint(new PatternDef().regexp("[a-zA-Z][0-9a-zA-Z_]*")
                    .message("{msg.error.validation.username.pattern}"))
            .property("password", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .property("fullName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("email", ElementType.FIELD).constraint(new EmailDef())
            .constraint(new SizeDef().max(64));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:25,代碼來源:SysUserUpdateValidator.java

示例11: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(SysRole.class).property("roleId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("roleName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new PatternDef().regexp("^(?!root$).+$").message("may not be root"))
            .property("roleCode", ElementType.FIELD)

            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:19,代碼來源:SysRoleUpdateValidator.java

示例12: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysUser.class)
            .property("username", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(16).min(3))
            .constraint(new PatternDef().regexp("[a-zA-Z][0-9a-zA-Z_]*")
                    .message("{msg.error.validation.username.pattern}"))
            .property("password", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("fullName", ElementType.FIELD)
            .constraint(new NotNullDef()).constraint(new SizeDef().max(32))
            .property("email", ElementType.FIELD)
            .constraint(new SizeDef().max(64)).constraint(new EmailDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:25,代碼來源:SysUserValidator.java

示例13: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping.type(ChangePasswordVo.class)
            .property("oldpassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("newpassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef())
            .property("retypepassword", ElementType.FIELD)
            .constraint(new SizeDef().max(16).min(6))
            .constraint(new NotNullDef());
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:21,代碼來源:PasswordValidator.java

示例14: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysMenu.class)
            .property("menuId", ElementType.FIELD)
            .constraint(new NotNullDef())
            .property("menuName", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .property("menuPath", ElementType.FIELD)
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"))
            .property("icon", ElementType.FIELD)
            .constraint(new SizeDef().max(32));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:24,代碼來源:SysMenuUpdateValidator.java

示例15: createValidator

import org.hibernate.validator.HibernateValidator; //導入依賴的package包/類
@Override
public Validator createValidator() {
    HibernateValidatorConfiguration configuration = Validation.byProvider(
            HibernateValidator.class).configure();

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    constraintMapping
            .type(SysRoute.class)
            .property("name", ElementType.FIELD)
            .constraint(new SizeDef().max(32))
            .constraint(new NotNullDef())
            .property("url", ElementType.FIELD)
            .constraint(new NotNullDef())
            .constraint(new SizeDef().max(128))
            .constraint(new PatternDef()
                    .regexp("(/:?[0-9a-zA-Z_]+)*")
                    .message("{msg.error.validation.routeUrl.pattern}"));
    return configuration.addMapping(constraintMapping).buildValidatorFactory()
            .getValidator();
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:22,代碼來源:SysRouteValidator.java


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