简体   繁体   中英

import javax.validation.constraints.NotEmpty; not found - Spring Boot

Why can't I use the @NotEmpty tag to perform validations?

This is my code:

package mx.com.gm.domain;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.Email;
import lombok.Data;

@Data
@Entity
@Table(name = "persona")
public class Persona implements Serializable{

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idPersona;

@NotEmpty
private String nombre;

@NotEmpty
private String apellido;

@NotEmpty
@Email
private String email;

@NotEmpty
private String telefono;
}

I'm trying to import javax.validation.constraints.NotEmpty but it doesn't show up in apache.netbeans.

I found the answer. It's because the dependency is no included in the web starter dependencies. You need to add it manually in your pom.xml file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM