英文:
why isn't @NotBlank not showing up as an import
问题
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
}
}
<!-- pom.xml -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
Please note that the images and non-code content from the original text have been omitted as per your request. If you need further assistance, feel free to ask.
英文:
Having an issue with my code
package 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
}
}
It's telling me that import javaz.validation.contraints.NotBlank doesn't exist, How do I install these on my IntelliJ
Im working on a project and I been having issues with this any import would be helpful, I'm using postman.
it just every time I check import javax.validation.constraints.NotBlank; is red I check options add dependency I get no result maven when I click find jar on web cant find it. How can I import this into my IntelliJ program?
Also here is my pom.xml code
<?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>
I added this
<dependency>
<groupId>**javax.validation**</groupId>
<artifactId>**validation-api**</artifactId>
<version>**2.0.1.Final**</version>
</dependency>
but the bold area is red dependency isn't found for these
Im still getting an error when I try to input dependency
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
答案1
得分: 6
关于 Spring Boot 项目,我添加了 "validation-api" 但 Postman 没有抛出错误,它允许存储空白字段(@NotBlank 不起作用)。然后我使用了以下内容 -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.4.1</version>
</dependency>
它起效了。
英文:
For Spring Boot project, I added "validation-api" but postman was not throwing error and it allowed to store Blank fields (@NotBlank was not working).
Then I used this -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.4.1</version>
</dependency>
and it worked.
答案2
得分: 3
需要添加validation-api依赖
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
英文:
You need to add validation-api dependency
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
答案3
得分: 1
你只需要添加这个依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
英文:
you just need to add this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论