@Validated 講解

SpringBoot 中使用@Validated 來檢驗數據,如果數據異常則拋出異常,統一處理。
例如,在Controller層中,對傳入的一個參數進行檢驗

@Validated TestDto testDto

對應的entity,TestDto

@Data
public class TestDto {
    @NotEmpty(message = "圖片不能爲空")
    private String id;
}

也可以使用 @Constraint 來增加自定義註解!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章