gpt4 book ai didi

java - 如何将GroupSequenceProvider级联到成员列表?

转载 作者:太空宇宙 更新时间:2023-11-04 11:42:56 24 4
gpt4 key购买 nike

您好,我有一个名为 car 的示例 bean,我想重新定义它的验证序列:

@GroupSequenceProvider(value = CarSequenceProvider.class)
public class Car{
@NotNull(groups = {groupOne.class})
private Boolean isGood;

@Valid
private List<Driver> drivers;

// getter/setter
}

这是我的驱动程序类

public class Driver{

@NotEmpty(groups = {groupTwo.class})
private List<String> skills;

//getter/setter
}

这是我的序列提供程序:

public class CarSequenceProvider implements DefaultGroupSequenceProvider<Car>{

@Override
public List<Class<?>> getValidationGroups(Car car) {
List<Class<?>> sequence = new ArrayList<Class<?>>();
sequence.add(Car.class);
sequence.add(groupOne.class);

if(car != null && car.IsGood()){
sequence.add(groupTwo.class);
}
}

基本上我只希望如果车好的话,所有驾驶员技能都不要为空。现在发生的情况是 @notEmpty 永远不会被调用,因为我的序列重新定义没有级联到驱动程序列表。那么可以级联吗?

非常感谢

最佳答案

Here @ConvertGroup comes into play which allows you during cascaded validation to use a different group than the originally requested one.

这是您尝试过的注释吗

来源:example-group-conversion-dedault-to-driver-checks

关于java - 如何将GroupSequenceProvider级联到成员列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42621728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com