【发布时间】:2022-07-19 14:54:44
【问题描述】:
具有多个字段的 bean 类。检查时,如果A为空,则检查B,否则不检查B。而且我需要根据不同的检查设置消息。
我有很多这样的验证,hibernate验证器可以轻松实现吗?
现在我是这样写的
public class Order
{
private String a;
private String b;
//.... other fields
}
public class Validation
{
public void valid(Order order) throws Exception
{
if (order.getA().isEmpty())
{
if (order.getB().isEmpty())
{
throw new Exception("xxx message ");
}
}
//....
}
}
【问题讨论】:
-
`if (order.getA().isEmpty() ^ order.getB().isEmpty() {
标签: java bean-validation hibernate-validator