@NotNull生效的前提必須在類上加了@Validated
@Validated 可以加在接口或類上
@NotNull 可以加在定義和實現 方法上(定義和實現方法的@Valid參數必須一致)
@NotNull 可以用在Controller和Service上
@Validated :org.springframework.validation.annotation
@NotNull :javax.validation.constraints
@Validated加在方法參數上或方法上不生效
public String say(@Validated @NotNull Person person){
System.out.println(person.getName());
return person.getName();
}
@Validated 在service中只能加到類上,加到方法或參數上無效