有什么办法可以控制休眠验证程序进行验证的顺序吗?

Is there any way to control the order of hibernate validator doing validation?

我们要求必须按特殊顺序验证对象的每个字段。

例如,我们有如下的 Person 对象:

public class Person {
    @NotNull
    private String firstName;
    @NotNull
    private String lastName;

    // getter and setter
}

当我使用 javax.validation.Validator 验证此对象时,我们需要确保始终先验证 firstName,然后再验证 lastName。 hibernate validator 是否有任何方法可以满足该要求?

您想使用组序列。特别是您可能想为您的实体重新定义默认组。另请参阅 Bean 验证规范定义的 Redefining the Default group for a class