@Validated和@NotNull

@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中只能加到类上,加到方法或参数上无效
原文地址:https://www.cnblogs.com/tiancai/p/14899216.html