Java Spring Boot 用户实体类示例:包含基本信息
以下是一个使用 Spring Boot 框架的 Java 类,包含用户基本信息:
package com.example.demo.user;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String email;
private String password;
public User() {
}
public User(String name, String email, String password) {
this.name = name;
this.email = email;
this.password = password;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + "'" +
", email='" + email + "'" +
", password='" + password + "'" +
"}";
}
}
这个类使用了 JPA 注解,因此可以将对象保存到数据库中。它包含了用户的基本信息,包括姓名、电子邮件和密码。此外,它还包含了默认的构造函数和带有参数的构造函数,以及 getter 和 setter 方法。最后,它还覆盖了 toString 方法,以便在需要时打印对象的字符串表示。
原文地址: https://www.cveoy.top/t/topic/naeT 著作权归作者所有。请勿转载和采集!