2311061234/src/main/java/com/vibevault/model/User.java
张雪尔 4e464d5957
Some checks are pending
autograde-final-vibevault / check-trigger (push) Waiting to run
autograde-final-vibevault / grade (push) Blocked by required conditions
更新 src/main/java/com/vibevault/model/User.java
2025-12-22 04:10:30 +08:00

82 lines
2.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.vibevault.model;
import jakarta.persistence.*;
/**
* 用户实体类
* 需要实现:
* - 将此类映射为数据库表 "users"
* - id 作为自增主键
* - username 必须唯一且不能为空
* - password 不能为空
* - [Challenge] 支持用户角色(如 ROLE_USER, ROLE_ADMIN
*/
@Entity // 实现:将此类映射为数据库表
@Table(name = "users") // 实现:指定表名为"users"
public class User {
@Id // 实现标记id为主键
@GeneratedValue(strategy = GenerationType.IDENTITY) // 实现id作为自增主键
private Long id;
@Column(nullable = false, unique = true) // 实现username必须唯一且不能为空
private String username;
@Column(nullable = false) // 实现password不能为空
private String password;
// [Challenge] 支持用户角色(如 ROLE_USER, ROLE_ADMIN
@Column(nullable = false) // 角色字段非空
private String role = "ROLE_USER"; // 默认角色为ROLE_USER
// 无参构造JPA必须
public User() {
}
// 2参数构造用户名+密码)
public User(String username, String password) {
this.username = username;
this.password = password;
}
// 3参数构造适配测试代码用户名+密码+角色)
public User(String username, String password, String role) {
this.username = username;
this.password = password;
this.role = role;
}
// 必须的getter/setter方法JPA操作实体需要
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}