@Valid object nested List object validation invalid solution

The controller is as follows:

public Objects flights(@RequestBody @Valid AForm aForm){
    
    
        return null;
    }

The form is as follows:

public class AForm {
    
    

    @NotNull(message = "数据更新时间必选")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    private Date updateTime;

    private List<ASubForm> updateList;
}

public class ASubForm {
    
    

    @NotBlank(message = "航班号必选")
    private String FlightNumber;

    @NotBlank(message = "航班日期必选")
    private String FlightDate;

    @NotBlank(message = "离港机场必选")
    private String DepAirport;

    @NotBlank(message = "目的机场必选")
    private String ArrAirport;
}

Problem:
When the controller calls, only the outer updateTime prompts that the data update time is required, and the flight number, flight date, etc. are empty and will not be checked.

Solution:
modify AForm, and add annotation @Valid to the list object to verify normally

public class AForm {
    
    

    @NotNull(message = "数据更新时间必选")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    private Date updateTime;

 	@Valid
    private List<ASubForm> updateList;
}

Guess you like

Origin blog.csdn.net/Tanganling/article/details/128792001