问题:The import javax.validation.constraints.NotNull cannot be resolved"
想要设置bean的验证:
@NotEmpty(message = "姓名不能为空")
@Size(min=2, max=20)
@Column(nullable = false, length = 20)
private String name;
@NotEmpty(message = "邮箱不能为空")
@Size(max=50)
@Email(message= "邮箱格式不对" )
@Column(nullable = false, length = 50, unique = true)
private String email;
@NotEmpty(message = "账号不能为空")
@Size(min=3, max=20)
@Column(nullable = false, length = 20, unique = true)
private String username;
@NotEmpty(message = "密码不能为空")
@Size(max=100)
@Column(length = 100)
private String password;
引入了import javax.validation.constraints.Size;
但该引入识别不了报错。
原因:Spring Boot需要单独的Validation依赖项
在依赖配置文件下加入如下依赖,以gradle build 为例:
implementation'org.springframework.boot:spring-boot-starter-validation'
更新配置,问题解决。