Bean Validation
Beispiele
“NotBlankIfPresent”
Da z.B @NotNull oder @NotBlank auch voraussetzt, dass der Wert nicht null sein darf, kann man z.B. die Annotation @Pattern verwenden:
@Pattern(regexp = "^(?!\\s*$).+", message = "May be null, but must not be blank.")
private String name;
Beispiel zur Verwendung der javax.validation.constraints.Pattern annotation
Links
- Übersicht möglicher Validierungs-Annotationen
- Difference Between @NotNull, @NotEmpty, and @NotBlank Constraints in Bean Validation