2

我正在使用 JDL (JHipster 5.8.1) 使用 DTO 选项定义我的域模型:

entity Event {
    title               String maxlength(128)             required,
    bannerUrl           String maxlength(256)             required,
    summary             String maxlength(256)             required
}

entity Tag {
    name                String maxlength(64)             required
}

entity Team {
    title           String maxlength(128) required,
    description     TextBlob
}

relationship ManyToMany {
    Event{tags} to Tag{events}
}

relationship OneToMany {
    Event{teams} to Team{event required}
}

relationship ManyToOne {
    Event{city} to City{events}
}

dto * with mapstruct

我试图定义包含多个可重用标签和多个团队的事件。目的是让 API 生成复合 JSON,其中包含所有标签和所有团队在请求的事件中(以避免 REST 中的 N+1 问题)

我希望在标签 <-> 事件和团队 <-> 事件之间获得双向关系。对于多对多关系,这是真的:我在 EventDTO 中看到了 TagDTO 的吸气剂。但是对于 OneToMany(也是 ManyToOne),我在 EventDTO 中看不到任何 getter,而在 Team 中没有看到 eventId getter:

public class EventDTO implements Serializable {

    private Long id;

    @NotNull
    @Size(max = 128)
    private String title;

    @NotNull
    @Size(max = 256)
    private String bannerUrl;

    @NotNull
    @Size(max = 256)
    private String summary;

    private Long cityId;

    private Set<TagDTO> tags = new HashSet<>();

dto * with mapstruct如果 eagerload=true,则生成的无行代码会生成带有所有子实体的预期 JSON,但这种方法可能会导致安全问题。

是否可以更正我的 JDL 以生成类似 childEntity 的 DTO 但不生成类似 childId 的 DTO?

4

0 回答 0