gpt4 book ai didi

java - 为什么@NotBlank 不显示为导入

转载 作者:行者123 更新时间:2023-12-05 08:50:12 25 4
gpt4 key购买 nike

我的代码有问题

enter image description here enter image description here包 com.example.demoSpring.student;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.lang.NonNull;

**import javax.validation.constraints.NotBlank;**
import java.util.UUID;

public class Students {
private final UUID studentId;

**@NotBlank**
private final String firstName;

**@NotBlank**
private final String lastName;

**@NotBlank**
private final String email;

@NonNull
private final Gender gender;

public Students(@JsonProperty("studentId") UUID studentId,
@JsonProperty("firstName") String firstName,
@JsonProperty("lastName") String lastName,
@JsonProperty("email") String email,
@JsonProperty("gender") Gender gender) {
this.studentId = studentId;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.gender = gender;
}

public UUID getStudentId() {
return studentId;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getEmail() {
return email;
}

public Gender getGender() {
return gender;
}

@Override
public String toString() {
return "Students{" +
"studentId=" + studentId +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
", gender=" + gender +
'}';
}

enum Gender{
MALE,FEMALE
}

}

它告诉我 import javaz.validation.contraints.NotBlank 不存在,我该如何在我的 IntelliJ 上安装它们

我正在做一个项目,但我一直对此有疑问,任何导入都会有所帮助,我正在使用 postman 。每次我检查 import javax.validation.constraints.NotBlank;是红色的我检查选项添加依赖项当我在网上单击查找 jar 时我没有得到任何结果 maven 无法找到它。如何将其导入我的 IntelliJ 程序?

还有我的pom.xml代码

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demoSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demoSpring</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>11</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>



<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>demoSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

我加了这个

<dependency>
<groupId>**javax.validation**</groupId>
<artifactId>**validation-api**</artifactId>
<version>**2.0.1.Final**</version>
</dependency>

但粗体区域为红色 未找到这些依赖项 enter image description here

当我尝试输入依赖项时仍然出现错误

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>

最佳答案

对于 Spring Boot 项目,我添加了“validation-api”,但 postman 没有抛出错误,它允许存储空白字段(@NotBlank 不工作)。然后我用了这个 -

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.4.1</version>
</dependency>

它奏效了。

关于java - 为什么@NotBlank 不显示为导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62630887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com