JHipster 踩坑之旅(2)-Managing relationships(1)

A bidirectional one-to-many relationship

双向一对多关系
举例:车主 与 车。车主可以有很多车,一辆车只能有一个车主。

Owner (1) <-----> (*) Car

先创建一个 owner 类
jhipster entity Owner
================= Owner =================
Fields
name (String)
age (Integer)
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Car
? What is the name of the relationship? car
? What is the type of the relationship? one-to-many
? What is the name of this relationship in the other entity? owner
然后创建一个 car 类
jhipster entity Car
================= Car =================
Fields
brand (String)
license (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Owner
? What is the name of the relationship? owner
? What is the type of the relationship? many-to-one
? When you display this relationship with Angular, which field from ‘Owner’ do you want to use? This field will be displayed as a String, so it cannot be a Blob id
? Do you want to add any validation rules to this relationship? No
现在在这两个实体之间有一对多的关系!在生成的AngularJS客户端UI上,将在Car中有一个下拉菜单来选择一个所有者。所有者可以通过id或者name自己设置来显示。

A unidirectional many-to-one relationship

单向的多对一关系
举例:多对一的单向关系意味着汽车知道他们的车主,但不是相反的。

Owner (1) <----- (*) Car

·从业务角度来看,您只能以这种方式使用您的实体。所以你不想有一个允许开发人员做一些没有意义的API。
·使用所有者实体时,您的性能收益会很小(因为它不必管理汽车集合)。
创建 owner 类
================= Owner =================
Fields
name (String)
age (Integer)
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
创建 Car 类
================= Car =================
Fields
brand (String)
license (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Owner
? What is the name of the relationship? owner
? What is the type of the relationship? many-to-one
? When you display this relationship with Angular, which field from ‘Owner’ do you want to use? This field will be displayed as a String, so it cannot be a Blob name
? Do you want to add any validation rules to this relationship? No
这将与前面的示例一样,但将无法向Owner实体添加或删除汽车。在生成的AngularJS客户端UI上,将在Car中有一个下拉菜单来选择一个所有者。
 
 
 

发表评论

电子邮件地址不会被公开。 必填项已用*标注