迁移实体类,并增加了领域模型(尝试使用event)
This commit is contained in:
parent
480a40f152
commit
ce3e462771
@ -3,6 +3,7 @@ package com.qqchen.deploy.backend.entity;
|
|||||||
import com.qqchen.deploy.backend.common.annotation.LogicDelete;
|
import com.qqchen.deploy.backend.common.annotation.LogicDelete;
|
||||||
import com.qqchen.deploy.backend.common.domain.Entity;
|
import com.qqchen.deploy.backend.common.domain.Entity;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
@ -18,11 +19,35 @@ import lombok.EqualsAndHashCode;
|
|||||||
@LogicDelete
|
@LogicDelete
|
||||||
public class UserRole extends Entity<Long> {
|
public class UserRole extends Entity<Long> {
|
||||||
|
|
||||||
@ManyToOne // 多对一关系
|
@ManyToOne(fetch = FetchType.LAZY) // 添加懒加载
|
||||||
@JoinColumn(name = "user_id") // 外键列
|
@JoinColumn(name = "user_id")
|
||||||
private User user; // 用户
|
private User user;
|
||||||
|
|
||||||
@ManyToOne // 多对一关系
|
@ManyToOne(fetch = FetchType.LAZY) // 添加懒加载
|
||||||
@JoinColumn(name = "role_id") // 外键列
|
@JoinColumn(name = "role_id")
|
||||||
private Role role; // 角色
|
private Role role;
|
||||||
|
|
||||||
|
// 添加构造方法
|
||||||
|
protected UserRole() {
|
||||||
|
// JPA需要无参构造方法
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserRole(User user, Role role) {
|
||||||
|
this.user = user;
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重写equals和hashCode方法,避免无限递归
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof UserRole)) return false;
|
||||||
|
UserRole userRole = (UserRole) o;
|
||||||
|
return getId() != null && getId().equals(userRole.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getClass().hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user