如何创建实体与自身的关系?例如,分层文件夹

问题描述 投票:1回答:2

我正在尝试创建一个分层文件夹结构。这是我的文件夹实体:

$ yo jhipster:entity Folder
The entity Folder is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? No
=================Folder=================
name (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? parentId
? What is the type of your field? Long
? Do you want to add validation rules to your field? No
=================Folder=================
name (String)
parentId (Long)
Generating field #3
? Do you want to add a field to your entity? No
=================Folder=================
name (String)
parentId (Long)

我正在尝试绘制我需要提供的jhipster实体生成器以使其工作。这就是我到目前为止......

Generating relationships with other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? Folder
? What is the name of the relationship? parent
? What is the type of the relationship? one-to-many
? What is the name of this relationship in the other entity? child

我是在正确的轨道上吗?如何创建孩子多对一关系?如果我尝试使用Folder实体创建它,我会收到警告。之后无法生成它。

jhipster
2个回答
1
投票

您可以使用https://jhipster.github.io/jdl-studio/写入jdl来创建实体。请访问https://jhipster.github.io/jhipster-uml/#jdl了解更多信息。这是一个与自身有关系的示例JDL:

entity RankProperties {
    rank Integer required,
    minExp Integer required,
    maxExp Integer required,
    maxStamina Integer required,
    maxAlly Integer required,
    maxTeam Integer required    
}
enum TaskMode {
    NO_CONTINUE_STAGE_COUNT,
    STAGE_COUNT,
    STAGE_ID
}

entity Task {
    taskMode TaskMode required,
    value Integer   required
}

relationship ManyToOne {
  Task{parent} to Task
}

dto all with mapstruct
service all with serviceClass

0
投票

我建议使用jdl模型。

entity A { property1 String }
relationship OneToMany {
   A{sons} to A{parent}
}

该模型生成一个Entity java类(忽略一些注释):

class A {
    @OneToMany(mappedBy="parent")
    private Set<A> sons = new HashSet<>();

    @ManyToOne
    private A parent;
}
© www.soinside.com 2019 - 2024. All rights reserved.