本文整理汇总了Java中javax.validation.Validation.buildDefaultValidatorFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Validation.buildDefaultValidatorFactory方法的具体用法?Java Validation.buildDefaultValidatorFactory怎么用?Java Validation.buildDefaultValidatorFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.Validation
的用法示例。
在下文中一共展示了Validation.buildDefaultValidatorFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.validation.Validation; //导入方法依赖的package包/类
public static void main(String[] args) throws NoSuchMethodException, SecurityException {
AutoRunHelper.run(App.class);
// 测试参数校验
App app = new App();
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
ExecutableValidator executableValidator = factory.getValidator().forExecutables();
Method method = App.class.getMethod("showEmail", String.class);
Object[] parameterValues = {"email"};
Set<ConstraintViolation<App>> violations = executableValidator.validateParameters(app, method, parameterValues);
String message = violations.iterator().hasNext() ? violations.iterator().next().getMessage() : "";
System.out.println("values:" + parameterValues[0].toString() + " size: " + violations.size() + " msg:" + message);
Object[] parameterValues2 = {"abc"};
violations = executableValidator.validateParameters(app, method, parameterValues2);
message = violations.iterator().hasNext() ? violations.iterator().next().getMessage() : "";
System.out.println("values:" + parameterValues2[0].toString() + " size: " + violations.size() + " msg:" + message);
}
示例2: initialize
import javax.validation.Validation; //导入方法依赖的package包/类
public void initialize(Configuration cfg) {
if ( !initialized ) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Properties props = cfg.getProperties();
init( factory, props );
}
}
示例3: testValid
import javax.validation.Validation; //导入方法依赖的package包/类
@Test
public void testValid() {
TextField text = new TextField();
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Binder<MyEntity> binder = new BeanValidationBinder<>(MyEntity.class);
binder.forField(text).withNullRepresentation("").bind("text");
MyEntity t = new MyEntity();
// valid
t.setText("bla");
binder.setBean(t);
assertTrue(validator.validate(t).isEmpty());
assertTrue(binder.validate().isOk());
text.setValue("");
assertNull(t.getText());
/*
* // invalid t.setText(""); binder.setBean(t);
* assertFalse(validator.validate(t).isEmpty());
* assertFalse(binder.validate().isOk());
*
* t.setText(null); binder.setBean(t);
* assertTrue(validator.validate(t).isEmpty());
* assertTrue(binder.validate().isOk());
*/
}
示例4: doValidation
import javax.validation.Validation; //导入方法依赖的package包/类
/**
* Validoi annettu bean:in siinä annettuja BeanValidation annotaatio-ehtoja vasten.
*
* @param bean
* Validoitava bean.
* @return Listaus löytyneistä validointivirheistä.
*/
public Set<ConstraintViolation<T>> doValidation(T bean) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<T>> errors = validator.validate(bean);
return errors;
}
示例5: init
import javax.validation.Validation; //导入方法依赖的package包/类
@Before
public void init() {
emFactory = Persistence.createEntityManagerFactory("DB");
em = emFactory.createEntityManager();
valFactory = Validation.buildDefaultValidatorFactory();
validator = valFactory.getValidator();
}
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:9,代码来源:NotStandardTest.java
示例6: JValidator
import javax.validation.Validation; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public JValidator(URL url) {
this.clazz = ReflectUtils.forName(url.getServiceInterface());
String jvalidation = url.getParameter("jvalidation");
ValidatorFactory factory;
if (jvalidation != null && jvalidation.length() > 0) {
factory = Validation.byProvider((Class)ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory();
} else {
factory = Validation.buildDefaultValidatorFactory();
}
this.validator = factory.getValidator();
}
示例7: setup
import javax.validation.Validation; //导入方法依赖的package包/类
@Before
public void setup() {
metadataService = mock(MetadataService.class);
flowPersistenceProvider = mock(FlowPersistenceProvider.class);
snapshotSerializer = mock(VersionedProcessGroupSerializer.class);
final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
validator = validatorFactory.getValidator();
registryService = new RegistryService(metadataService, flowPersistenceProvider, snapshotSerializer, validator);
}
示例8: validateTodoValid
import javax.validation.Validation; //导入方法依赖的package包/类
@Test
public void validateTodoValid() {
ToDo toDo = new ToDo("[email protected]","caption", "description 1", 6);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<ToDo>> constraintViolations = validator.validate(toDo);
assertTrue(constraintViolations.isEmpty());
}
示例9: checkParam
import javax.validation.Validation; //导入方法依赖的package包/类
public static <E> void checkParam(E obj, Class mafExceptionClass, Integer respCode, Class... validateGroup) throws Exception
{
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Validator validator = vf.getValidator();
Set<ConstraintViolation<Object>> set = validator.validate(obj, validateGroup);
for(ConstraintViolation<Object> cv : set)
{
Constructor constructor = mafExceptionClass.getConstructor(int.class, String.class);
MafiaException mafException = (MafiaException) constructor.newInstance(respCode, cv.getMessage());
throw mafException;
}
}
示例10: Jsr303Validator
import javax.validation.Validation; //导入方法依赖的package包/类
/**
* 构造函数
*
* @param className
* 当前调用的接口类
* @param customValidator
* Validator的实现类,传null默认为javax.validation自动查找,否则按指定来
* @throws ClassNotFoundException 自定义实现类找不到
*/
@SuppressWarnings("unchecked")
public Jsr303Validator(String className, String customValidator) throws ClassNotFoundException {
this.clazz = ClassLoaderUtils.forName(className);
javax.validation.ValidatorFactory factory;
if (customValidator != null && customValidator.length() > 0) {
factory = Validation.byProvider(ClassLoaderUtils.forName(customValidator))
.configure().buildValidatorFactory();
} else {
factory = Validation.buildDefaultValidatorFactory();
}
this.validator = factory.getValidator();
}
示例11: MowerPosition
import javax.validation.Validation; //导入方法依赖的package包/类
public MowerPosition(int x, int y, Direction direction, Lawn lawn) {
this.x = x;
this.y = y;
this.direction = direction;
this.lawn = lawn;
this.vf = Validation.buildDefaultValidatorFactory();
}
示例12: getValidator
import javax.validation.Validation; //导入方法依赖的package包/类
@Bean(name="validator")
@Autowired
public Validator getValidator() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
return factory.getValidator();
}
示例13: setUp
import javax.validation.Validation; //导入方法依赖的package包/类
@Before
public void setUp() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
示例14: userLogin
import javax.validation.Validation; //导入方法依赖的package包/类
/**
* 用户登录
* @param req
* @param request
* @return
*/
@RequestMapping(value = "/userLogin", method = RequestMethod.POST)
@ResponseBody
public BaseResult userLogin(@RequestBody JSONObject req, HttpServletRequest request) {
log.info("/login/userLogin.do start.. time:{}", DateUtil.nowStr());
HttpSession session = request.getSession();
try {
String userName = req.getString("userName");
String password = req.getString("password");
String verifyCode = req.getString("verifyCode");
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<LoginParam>> constraintViolations = validator
.validate(new LoginParam(userName, password, verifyCode));
for (ConstraintViolation<LoginParam> constraintViolation : constraintViolations) {
return BaseResult.returnErrorMessage(constraintViolation.getMessage());
}
if (!imageCaptchaService.validateResponseForID(session.getId(), verifyCode)) {
log.info("用户输入的验证图形验证码有误!login verifyCode:{}", verifyCode);
return BaseResult.returnErrorMessage(1, "您输入的验证码不正确!");
}
log.info("/login/userLogin.do data:{}", req.toJSONString());
UmUser user = loginService.selectUserByLoginName(userName);
if (null == user) {
return BaseResult.returnErrorMessage("账号或密码错误!");
}
String md5_password = user.getPassword();
if (StringUtils.isEmpty(md5_password) || !md5_password.equals(EncryptUtil.md5Encrypt(password))) {
return BaseResult.returnErrorMessage("密码错误!");
}
BigDecimal state = user.getState();
if (null != state && state.compareTo(new BigDecimal(1)) == 0) {
return BaseResult.returnErrorMessage("账号未激活或冻结!");
}
BigDecimal id = user.getId();
List<String> groupIds = loginService.selectGroupIdsByUserId(id);
List<String> roleIds = loginService.selectRoleIdsByUserId(id);
user.setLoginTime(DateUtil.nowStr());
Set<String> propertySet = new HashSet<String>();
propertySet.add("password");
propertySet.add("id");
JSONObject res = SerializerUtil.skipByName(JSONObject.toJSON(user), propertySet);
res.put("UserGroups", groupIds);
res.put("UserRoles", roleIds);
session.setAttribute("cache_user", res);
session.setAttribute("cache_user_id", id);
// 添加登录日志
UmLoginLog loginlog = new UmLoginLog();
loginlog.setId(StringUtil.getRandom(32));
loginlog.setUserId(id);
loginlog.setDeviceName(WebUtil.getDeviceName(request));
loginlog.setHostName(WebUtil.getLocalName(request));
loginlog.setIpAddress(WebUtil.getRemoteAddr(request));
loginlog.setLoginName(user.getUserName());
loginlog.setLoginTime(DateUtil.Timestamp());
loginlog.setLogoutTime(DateUtil.Timestamp());
loginlog.setState(new BigDecimal(0));
loginService.insertLoginLog(loginlog);
log.info("用户登录成功:{}", res.toJSONString());
return BaseResult.returnSuccessMessage(res, "用户登录成功!");
} catch (Exception e) {
log.error("/login/userLogin.do 用户登录失败!{}", e.getMessage());
e.printStackTrace();
}
return BaseResult.returnErrorMessage("用户登录失败!");
}
示例15: setup
import javax.validation.Validation; //导入方法依赖的package包/类
@Setup(Level.Iteration)
public void setup() {
validatorFactory = Validation.buildDefaultValidatorFactory();
validator = validatorFactory.getValidator();
}