今天在做后台校验的时候发现,@Valid找不到,@Valid是spring-boot-starter-validation依赖里的,而这个依赖是spring-boot-starter-web里自带的
1.SpringBoot2.2.0RELEASE版本的web依赖里
2.SpringBoot2.6.6 版本的web依赖里
对比后得出结论,SpringBoot2.6.6版本里把校验依赖移除了,所以要是用的话需要单独引入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.6.6</version>
</dependency>
我这里用的springboot版本是2.6.6所以引的校验依赖也是2.6.6,使用时换成自己springboot对应的版本就行
注:在springboot2.3.0之后这个依赖在web里被移除了