我有一个类,其中我有两个类型为boolean的属性。条件都不应该相同,即如果一个属性保持false值,则其他必须保持true值,反之亦然。我正在使用net。验证的sf.oval依赖。如何实现上述场景。是否可能?谢谢
我的班级
public class Modality {
private boolean fp;
private boolean otp;
public boolean isFp() {
return fp;
}
public void setFp(boolean fp) {
this.fp = fp;
}
public boolean isOtp() {
return otp;
}
public void setOtp(boolean otp) {
this.otp = otp;
}
@Override
public String toString() {
return "Modality [fp=" + fp + ", otp=" + otp + "]";
}
}
答案 0 :(得分:0)
试试这个:
public void setOtp(boolean otp) {
this.otp = otp;
this.fp = !otp;
}
public void setFp(boolean fp) {
this.fp = fp;
this.otp = !fp;
}
答案 1 :(得分:0)
使用@NotEqualToField注释?
public class Modality {
private boolean fp;
@NotEqualToField("fp")
private boolean otp;
}