如何设计复杂的entity及对应的数据库表
答案:1 悬赏:30 手机版
解决时间 2021-02-01 13:58
- 提问者网友:玫瑰园
- 2021-02-01 02:07
如何设计复杂的entity及对应的数据库表
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-02-01 03:03
public class User {
private Integer id;
private String userName;
private EntityA entityA;
private List entityBs;
...
@Id
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
@Column(name = "ID", length=11)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "user_name", length = 20)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
...
//to-do: EntityA
//to-do: EntityBs
}
-----------------------------------------------------------------------------------------
@Entity
public class EntityA(){
private Integer id;
private String name;
...
@Id
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
@Column(name = "ID", length=11)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", length = 20)
public String getName() {
return name;
}
public void setUserName(String name) {
this.name = name;
}
...
}
@Entity
public class EntityB(){
private Integer id;
private String name;
...
private Integer id;
private String userName;
private EntityA entityA;
private List
...
@Id
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
@Column(name = "ID", length=11)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "user_name", length = 20)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
...
//to-do: EntityA
//to-do: EntityBs
}
-----------------------------------------------------------------------------------------
@Entity
public class EntityA(){
private Integer id;
private String name;
...
@Id
@GenericGenerator(name = "generator", strategy = "increment")
@GeneratedValue(generator = "generator")
@Column(name = "ID", length=11)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "name", length = 20)
public String getName() {
return name;
}
public void setUserName(String name) {
this.name = name;
}
...
}
@Entity
public class EntityB(){
private Integer id;
private String name;
...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯