1. 程式人生 > 其它 >關於使用JSR303資料檢驗報錯問題

關於使用JSR303資料檢驗報錯問題

技術標籤:spring bootmaven

關於使用JSR303資料檢驗報錯問題

在新版的springboot中存在這樣一個問題,使用JSR303資料校驗會報錯。
如下圖:
在這裡插入圖片描述
使用@Validated註解沒有報紅,但是使用@Email校驗註解的時候報紅

  • 解決方法如下:
    在pom.xml中匯入JSR303的springboot啟動器

可以到Maven中去搜索Spring Boot Starter Validation
也可以使用下方的** 2.3.6.RELEASE**版本的啟動器(同樣是我在Maven中找的,方便大家的使用,需要其他版本可自行去Maven找)

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation -->
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> <version>2.3.6.RELEASE</version> </dependency>

匯入後報紅問題就可以解決了!