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



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

$ 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实体创建它,则会收到警告。之后没有办法生成它。

您可以使用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

我建议使用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;
}

相关内容

最新更新