Cross field validation with Hibernate Validator (JSR 303)

前端 未结 15 1751
渐次进展
渐次进展 2020-11-22 02:37

Is there an implementation of (or third-party implementation for) cross field validation in Hibernate Validator 4.x? If not, what is the cleanest way to implement a cross fi

15条回答
  •  名媛妹妹
    2020-11-22 02:46

    You need to call it explicitly. In the example above, bradhouse has given you all the steps to write a custom constraint.

    Add this code in your caller class.

    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
    
    Set> constraintViolations = validator.validate(yourObject);
    

    in the above case it would be

    Set> constraintViolations = validator.validate(objAccountCreateForm);
    

提交回复
热议问题