1.导入依赖
<dependency> <groupId>jakarta.validation</groupId> <artifactId>jakarta.validation-api</artifactId> <version>2.0.2</version> </dependency>
2.给要校验的javaBean上标注校验注解
@Validated public class Dog
给对象属性添加校验注解
@Email(message = "邮箱格式错误") private String name;