first step
Import the jar package for data verification
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Second step
Use annotations in entity classes
@Configuration
@ToString
@Data
@AllArgsConstructor
@NoArgsConstructor
@ConfigurationProperties(prefix = "haidong")
@Validated
public class dog {
private Integer id;
private String name;
@Email
private String email;
}
third step
Write value in yml file
haidong:
id: 1
name: haidong
email: 123 --这里故意把邮箱格式写错 进行测试
the fourth step
test
![Insert picture description here](https://img-blog.csdnimg.cn/20210325101502503.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTk2NzM3NQ==,size_16,color_FFFFFF,t_70)
We changed the email format to correct and tested
haidong:
id: 1
name: haidong
email: 123@qq.com --这里写正确的邮箱格式
test
![Insert picture description here](https://img-blog.csdnimg.cn/20210325101912810.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTk2NzM3NQ==,size_16,color_FFFFFF,t_70)