1
實現交叉場驗證的最佳方式是什麼?如果字段a爲空,那麼字段b必須> 10,等等?跨場驗證在比賽中?
實現交叉場驗證的最佳方式是什麼?如果字段a爲空,那麼字段b必須> 10,等等?跨場驗證在比賽中?
如何在該字段上創建瞬態僞屬性和自定義驗證規則?
@Entity
public class Foo extends Model {
public String a;
public int b;
@Transient
@CheckWith(CCheck .class)
transient boolean c;
public boolean getC() {
return a != null || b > 10;
}
static class CCheck extends Check {
public boolean isSatisfied(Object myObject, Object val) {
return Boolean.valueOf(val);
}
}
}
如果不工作,那麼可能是你需要創建一個嵌入類a
和「B」,並創建了與該類領域的定製檢查。
我會在我的控制器動作直接做到這一點:
public static void action(@Required int a, @Required int b)
{
if (a == null)
{
validation.isTrue(b > 10).message("b must be greater than 10");
}
}