如何在JHipster 3.x中创建一个包含相关实体列表的实体视图? [英] How to create an entity view with list of related entities in JHipster 3.x?

查看:89
本文介绍了如何在JHipster 3.x中创建一个包含相关实体列表的实体视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JHipster的新手,所以忍受我:)。我想在实体详细信息视图中显示相关实体的列表。我怎样才能做到这一点?由于这在此应用程序中很常见,因此最好采用一种通用方式来执行此操作,而不是修改每个实体(例如,通过修改生成器),但如果没有其他方法,则每个实体编辑都可以。



一个例子:我有课程,每门课程可能有许多课程,学生和客户连接。现在,在课程字段下方的课程详细信息视图中,我希望每个相关课程,学生和客户都有三个列表(例如,类似于SalesForce所做的)。



<问题有两个方面:我如何获得正确的数据(序列化),以及如何更改视图?后者(更改视图)似乎很简单,如果我手动为每个实体做,但很高兴生成它。



这似乎是一个常见的UX主题。是否有一个示例应用程序覆盖此用例?



感谢您的任何指示!

解决方案

简而言之:



1)你让你的 CourseResource 分发急切的<$获取的实体c $ c>课程,在您的课程集中有 @JsonIgnore 。最后,通过调用一个课程,JSON应该包含相关实体。



详细(编辑)



考虑一下,你用这样的JDL生成你的应用程序:

 实体课程{
courseName String
}

实体课程{
lessonName字符串
}

关系OneToMany {
课程{课程}到课程
}

然后先去课程 class并将Set更改为以下内容:

  @OneToMany(mappedBy = course,fetch = FetchType.EAGER)
// @ JsonIgnore - 删除此
私有Set< Lesson> lessons = new HashSet<>();

这是最快速的方式,但不是最常用的方式,因为每次查询课程时,你都加入也是如此。为了避免这种情况,您必须在您的存储库中构建一些@Query,然后手动加入...但我现在将保持简单。



删除@ JsonIgnore将导致课程隐含地成为课程表示的一部分,因此您将获得在UI中可视化的所有选项



2)找到显示它的方法,以你想要的方式



一般来说,我觉得拥有一些发电机似乎是一个好主意,但它可能比你想象的更难。比如,如何表示数据。如果您与该实体有多个关系,您会使用制表符吗?如果选项卡,但只有一个关系,那么选项卡是否仍然足够?是否更多关于这一点,仍然足以在JHipsters中央发电机中做出决定,或者这应该对开发者开放?



我认为值得讨论,但不过可以做一些JHipster模块来实现这个目标



最好的问候



PS:如果我的回答很简短,问我...现在已经很晚了,我懒得贴上一个完整的答案:)


New to JHipster, so bear with me :). I'd like to display lists of related entities on an entity detail view. How can I do that? Since this is common in this application, it would be best to have a generic way of doing this instead of modifying each entity (e.g. by modifying the generator), but per entity editing is OK if there is no other way.

An example: I have Courses and each Course may have many Lessons, Students and Clients connected. Now on the Course detail view below the Course fields I'd like to have three lists for each of the related Lessons, Students and Clients (e.g. similar to what SalesForce does).

The question has two sides: how can I get the proper data (serialization), and how can I change the view? The latter (change view) seems to be simple if I do it by hand for each entity, but would be nice to have it generated.

This seems to be a common UX theme. Is there a sample application somewhere covering this use case?

Thanks for any pointers!

解决方案

In short:

1) you make your CourseResource delievering eager fetched entities of Course, which have no @JsonIgnore over your Set of lessons. In the end, by calling one course, the JSON should contain the related entities.

in detail (edit):

consider, you generated your app with a JDL like this:

entity Course {
    courseName String
}

entity Lesson {
    lessonName String
}

relationship OneToMany {
    Course{lesson} to Lesson
}

Then first go to Course class and change the Set to the following:

@OneToMany(mappedBy = "course", fetch = FetchType.EAGER)
//@JsonIgnore - remove this
private Set<Lesson> lessons = new HashSet<>();

This is the quickiest way, but not the most perfomant, since everytime you query courses, you join on lessions, too. To avoid that, you must build some @Query into your repository where you manually join to that...but I will keep it simple for now.

The removal of @JsonIgnore will lead to the lessons implicitly being part of your Course representation, so you will got all options to visualize this in the UI

2) find some way to display it, in a way you want

generally I feel it seems to be a good idea of having some generator, but it might be harder than you think. Like, how to represent the data. If you got multiple relationships to that entity, will you use tabs? If tabs, but there is only one relation ship, does the tab still is adequate? Is that more on this, still adequate to decide this in JHipsters central generator, or this should be open for the developer?

I think, it worths a discussion, but nevertheless there could be done some JHipster module to accomplish this

Best Regards

P.S.: if my answer was to short, ask me on...it's just late and I am lazy to paste down a full blown answer :)

这篇关于如何在JHipster 3.x中创建一个包含相关实体列表的实体视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆