當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JSR303数据校验-2021新版
生活随笔
收集整理的這篇文章主要介紹了
JSR303数据校验-2021新版
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一步
導入數據校驗的jar包
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId> </dependency>第二步
在實體類使用注解
@Configuration @ToString @Data @AllArgsConstructor @NoArgsConstructor @ConfigurationProperties(prefix = "haidong") @Validated //數據校驗的注解 public class dog {private Integer id;private String name;@Email //校驗你的郵箱格式是否正確private String email; }第三步
在yml文件里寫值
haidong:id: 1name: haidongemail: 123 --這里故意把郵箱格式寫錯 進行測試第四步
測試
我們把郵箱格式改成正確在測試
haidong:id: 1name: haidongemail: 123@qq.com --這里寫正確的郵箱格式測試
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的JSR303数据校验-2021新版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: @configurationproper
- 下一篇: 使用yml多环境配置