Cross field validation with Hibernate Validator (JSR 303)

前端 未结 15 1750
渐次进展
渐次进展 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:56

    I suggest you another possible solution. Perhaps less elegant, but easier!

    public class MyBean {
      @Size(min=6, max=50)
      private String pass;
    
      private String passVerify;
    
      @AssertTrue(message="passVerify field should be equal than pass field")
      private boolean isValid() {
        return this.pass.equals(this.passVerify);
      }
    }
    

    The isValid method is invoked by the validator automatically.

提交回复
热议问题