自引用实体

发布于 2024-11-08 13:41:55 字数 172 浏览 5 评论 0原文

我有一个名为 person 的实体。 每个有三个字段:

性别(男,女) 母亲(自称人) 父亲(自我引用人员)

现在,在我看来 jspx,我希望两个选定的字段仅在母亲选择中显示女性人员,在父亲字段中显示男性人员。最好的方法是什么?

I have an entity called person.
Each person has three fields :

sexe (male, female)
mother (self referenced to person)
father (self referenced to person)

Now, in my view jspx, I would like the two selected fields to only display female personn in the mother select and male personns in the father field. What would be the best way to do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2024-11-15 13:41:55

首先,您应该创建动态查找器来按性别获取人员。在 Roo 控制台中输入:

finder list

然后找到类似 findPeopleBySex 的内容并输入:

finder add --finderName findPeopleBySex

如果您不想搭建此查找器的脚手架,可以将 exposeFinders = false 添加到 @RooWebScaffold PersonController 注释。

然后你应该打开你的 PersonController (我想它的主体是空的)并放置如下内容:

@ModelAttribute("men")
public Collection<Person> populateMen() {
    return Person.findPeopleBySex(Gender.Male).getResultList();
}

@ModelAttribute("women")
public Collection<Person> populateWomen() {
    return Person.findPeopleBySex(Gender.Female).getResultList();
}

最后打开你的 {project_root}/src/main/webapp/WEB-INF/views /people/create.jspx 然后找到以下几行:

    <field:select field="mother" id="c_xxx_Person_mother" itemValue="id" items="${people}" path="/people" z="xxx"/>
    <field:select field="father" id="c_xxx_Person_father" itemValue="id" items="${people}" path="/people" z="xxx"/>

并将其更改为:

    <field:select field="mother" id="c_xxx_Person_mother" itemValue="id" items="${women}" path="/people" z="xxx"/>
    <field:select field="father" id="c_xxx_Person_father" itemValue="id" items="${men}" path="/people" z="xxx"/>

确保 z 属性(哈希码)的值变为 用户管理。这意味着Roo将来不会改变它。

现在您可以运行您的应用程序并查看结果。

First of all, you should create dynamic finder to get persons by sex. Type in Roo console:

finder list

Then find something like findPeopleBySex and type:

finder add --finderName findPeopleBySex

If you don't want to scaffold this finder you can add exposeFinders = false to the @RooWebScaffold annotation of your PersonController.

Then you should open your PersonController (which body is empty I suppose) and place there something like the following:

@ModelAttribute("men")
public Collection<Person> populateMen() {
    return Person.findPeopleBySex(Gender.Male).getResultList();
}

@ModelAttribute("women")
public Collection<Person> populateWomen() {
    return Person.findPeopleBySex(Gender.Female).getResultList();
}

Finally open your {project_root}/src/main/webapp/WEB-INF/views/people/create.jspx then find the following lines:

    <field:select field="mother" id="c_xxx_Person_mother" itemValue="id" items="${people}" path="/people" z="xxx"/>
    <field:select field="father" id="c_xxx_Person_father" itemValue="id" items="${people}" path="/people" z="xxx"/>

And change them to be:

    <field:select field="mother" id="c_xxx_Person_mother" itemValue="id" items="${women}" path="/people" z="xxx"/>
    <field:select field="father" id="c_xxx_Person_father" itemValue="id" items="${men}" path="/people" z="xxx"/>

Make sure the value of z attribute (hash code) become user-managed. It means Roo will not change it in future.

Now you can run your application and see the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文