[英]@NotNull in spring boot not working as expected
This is my DTO class:这是我的 DTO class:
public class AppDTO implements Serializable {
private String appId;
private Date dateCreated;
@AppFeaturesValidation
private Set<AppFeature> appFeatures;
}
The @AppFeaturesValidation validate the content of appFeatures. @AppFeaturesValidation 验证 appFeatures 的内容。
This is the AppFeature class:这是 AppFeature class:
public class AppFeature {
private String packageId;
@NotNull
private Boolean isEnabled;
@NotNull
private Boolean isDisplayed;
}
When I send to this value null - it gets it.当我发送到这个值 null - 它得到它。 In the same project, a different type using @NotNull is working.
在同一个项目中,使用 @NotNull 的不同类型正在工作。 The same imports for this annotation, just a simpler object:
此注释的相同导入,只是一个更简单的 object:
public class packDTO implements Serializable {
private String packId;
private Date dateCreated;
@NotNull
private Boolean clone;
}
I had to add @Valid for the appFeatures Set, so the validations will be checked for each of the elements.我必须为 appFeatures 集添加 @Valid,因此将检查每个元素的验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.