1.添加来自 GlassFish 的 javax.el 依赖项
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
2.使用校验注解
message也可以是具体的内容,这里是errorcode
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.constraints.Email;
@Data
public class User {
@NotBlank(message = "tel")
private String tel;
@NotBlank(message= "address")
private String address;
@NotBlank(message=