When using JSR-303 annotations to perform bean validation, what is the difference between annotating the field versus the getter?
Is one approach recommended over the other?
Annotation on field
public class Person {
@NotBlank
private String firstName;
public String getFirstName() {
return firstName;
}
public String setFirstName(String firstName) {
this.firstName = firstName;
}
}
Annotation on getter
public class Person {
private String firstName;
@NotBlank
public String getFirstName() {
return firstName;
}
public String setFirstName(String firstName) {
this.firstName = firstName;
}
}