C
C
Chvalov2018-03-26 04:23:27
Hibernate
Chvalov, 2018-03-26 04:23:27

What is the difference between @NotEmpty, @NotBlank and @NotNull?

I'm doing form validation in Spring using javax validation
But something didn't get the difference between annotations @NotNull, @NotBlankand @NotEmpty?
Oh, and even in the Oracle documentation I came across this code :

public class Name {
    @NotNull
    @Size(min=1, max=16)
    private String firstname;

    @NotNull 
    @Size(min=1, max=16)
    private String lastname;
    ...
}
and here I have a question, why use @NotNullif we have @Sizein which the minimum length is set ( min=1 ) ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chvalov, 2018-03-26
@Chvalov

String name = null;
NotNull = false
NotEmpty = false
NotBlank = false

String nam = "";
NotNull = true
NotEmpty = false
NotBlank = false

String name = "  ";
NotNull = true
NotEmpty = true
NotBlank = false

String name = "zojian"
NotNull = true
NotEmpty = true
NotBlank = true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question