本文整理匯總了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();
}
示例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();
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}