Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 对象Bean验证的Spring启动列表_Spring Boot_Validation_Bean Validation - Fatal编程技术网

Spring boot 对象Bean验证的Spring启动列表

Spring boot 对象Bean验证的Spring启动列表,spring-boot,validation,bean-validation,Spring Boot,Validation,Bean Validation,我有一颗豆子 @Data @NoArgsConstructor public final class PersonRequest { @NotNull @JsonProperty("nameList") private List<Person> nameList; } 我正在发送JSON请求,并在我的控制器中添加了@Valid。我发送的请求如下: { "nameList": [

我有一颗豆子

@Data
@NoArgsConstructor
public final class PersonRequest {

    @NotNull
    @JsonProperty("nameList")
    private List<Person> nameList;

   

}
我正在发送JSON请求,并在我的控制器中添加了
@Valid
。我发送的请求如下:


{
    "nameList": [
        {
            "id": 1,
            "name": "John"
        },
        {
            "id": 2,
            "name": "Alex"
        }
    ]
}
当我在没有
id
name
未验证的情况下发送请求时。我尝试使用
@有效的私有列表名称列表也是,但没有运气。我使用SpringBoot2.3.2

更新:

当我再添加一个属性时,当我在请求中传递日期时,这也表示请求不正确

    @NotNull
    @JsonProperty("startTime")
    @DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss", iso = 
                              DateTimeFormat.ISO.DATE_TIME)
    @Valid
    private LocalDateTime startTime;

控制器中的
@Valid
注释触发作为请求正文传递的
PersonRequest
对象的验证。要同时验证
PersonRequest
中包含的
Person
对象,还需要使用
@Valid
对该字段进行注释

@Data
@NoArgsConstructor
public final class PersonRequest {

    @NotNull
    @JsonProperty("nameList")
    @Valid
    private List<Person> nameList;
}
@数据
@诺尔格构装师
公共最终类个人请求{
@NotNull
@JsonProperty(“名称列表”)
@有效的
私人名单;
}

谢谢托马斯,当我再添加一个属性时,
@NotNull@JsonProperty(“startTime”)@DateTimeFormat(pattern=“yyyy-MM-dd'T'hh:MM:ss”,iso=DateTimeFormat.iso.DATE\u-TIME)@Valid private LocalDateTimestartTime当我传入请求时,这也表示请求不正确。不幸的是,不是只有一个参数,当我传入有效的JSON时,它表示请求不正确。Thomas您是正确的,这是库中冲突的问题。非常感谢。使用
String
时,建议使用
@NotBlank
而不是
@NotNull
。谢谢!同意!
@Data
@NoArgsConstructor
public final class PersonRequest {

    @NotNull
    @JsonProperty("nameList")
    @Valid
    private List<Person> nameList;
}