SpringBoot 中使用@Validated 來檢驗數據,如果數據異常則拋出異常,統一處理。
例如,在Controller層中,對傳入的一個參數進行檢驗
@Validated TestDto testDto
對應的entity,TestDto
@Data
public class TestDto {
@NotEmpty(message = "圖片不能爲空")
private String id;
}
也可以使用 @Constraint 來增加自定義註解!
SpringBoot 中使用@Validated 來檢驗數據,如果數據異常則拋出異常,統一處理。
例如,在Controller層中,對傳入的一個參數進行檢驗
@Validated TestDto testDto
對應的entity,TestDto
@Data
public class TestDto {
@NotEmpty(message = "圖片不能爲空")
private String id;
}
也可以使用 @Constraint 來增加自定義註解!