2311061111/src/main/java/com/vibevault/model/User.java
VibeVault User d6a4bd92e6
Some checks failed
autograde-final-vibevault / check-trigger (push) Successful in 12s
autograde-final-vibevault / grade (push) Failing after 43s
完成作业
2025-12-14 01:10:20 +08:00

75 lines
1.5 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")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true, nullable = false)
private String username;
@Column(nullable = false)
private String password;
// [Challenge] 用户角色,默认为 ROLE_USER
@Column(nullable = false)
private String role = "ROLE_USER";
protected User() {
}
public User(String username, String password) {
this.username = username;
this.password = password;
}
public User(String username, String password, String role) {
this.username = username;
this.password = password;
this.role = role;
}
public Long getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}