【问题标题】:@NotNull in spring boot not working as expected春季启动中的@NotNull 无法按预期工作
【发布时间】:2021-06-13 10:47:38
【问题描述】:

这是我的 DTO 课程:

public class AppDTO implements Serializable {

    private String appId;

    private Date dateCreated;

    @AppFeaturesValidation
    private Set<AppFeature> appFeatures;

}

@AppFeaturesValidation 验证 appFeatures 的内容。

这是 AppFeature 类:

public class AppFeature {

    private String packageId;

    @NotNull
    private Boolean isEnabled;

    @NotNull
    private Boolean isDisplayed;

}

当我发送到这个值 null - 它得到它。 在同一个项目中,使用 @NotNull 的不同类型正在工作。 此注解的导入相同,只是一个更简单的对象:

public class packDTO implements Serializable {

    private String packId;

    private Date dateCreated;

    @NotNull
    private Boolean clone;

}

【问题讨论】:

    标签: java spring spring-boot annotations nullable


    【解决方案1】:

    我必须为 appFeatures 集添加 @Valid,因此将检查每个元素的验证。

    【讨论】:

      猜你喜欢
      • 2015-11-21
      • 2014-10-07
      • 1970-01-01
      • 2018-01-13
      • 2021-07-15
      • 1970-01-01
      • 2017-04-04
      • 2017-05-11
      • 1970-01-01
      相关资源
      最近更新 更多