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");
}
}