Hibernate 多对一映射和Struts2 jquery网格

Hibernate 多对一映射和Struts2 jquery网格,hibernate,struts2,many-to-one,jqgrid,Hibernate,Struts2,Many To One,Jqgrid,我正在查看showcase中的struts2 jquery网格。我可以理解如何将对象列表发送到网格模型,但在示例中,对象很简单,没有对象属性。但是在我的例子中,我的模型类如下所示: public class Student( private String first_name; private String last_name; private Person father; private Person mother; // an attribute of another class

我正在查看showcase中的struts2 jquery网格。我可以理解如何将对象列表发送到网格模型,但在示例中,对象很简单,没有对象属性。但是在我的例子中,我的模型类如下所示:

public class Student(
 private String first_name;
 private String last_name;
 private Person father;
 private Person mother; // an attribute of another class

 // other attributes, getters and setters

}
<s:url id="remoteurl" action="jsontable"/>
    <sjg:grid
        id="gridtable"
        caption="Customers Examples"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        gridModel="gridModel"
        rowList="10,15,20"
        rowNum="15"
        rownumbers="true"
        resizable="true"
        resizableAnimate="true"
        resizableGhost="true"
        resizableHandles="all"
    >
        <sjg:gridColumn name="id" index="id" title="ID" width="30" formatter="integer" sortable="false"/>
        <sjg:gridColumn name="name" index="name" title="Name" width="250" sortable="true"/>
        <sjg:gridColumn name="country" index="country" title="Country" sortable="false"/>
        <sjg:gridColumn name="city" index="city" title="City" sortable="false"/>
        <sjg:gridColumn name="creditLimit" index="creditLimit" title="Credit Limit" align="right" formatter="currency" sortable="false"/>
    </sjg:grid>
  </div>
在样本中,他们有如下特点:

public class Student(
 private String first_name;
 private String last_name;
 private Person father;
 private Person mother; // an attribute of another class

 // other attributes, getters and setters

}
<s:url id="remoteurl" action="jsontable"/>
    <sjg:grid
        id="gridtable"
        caption="Customers Examples"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        gridModel="gridModel"
        rowList="10,15,20"
        rowNum="15"
        rownumbers="true"
        resizable="true"
        resizableAnimate="true"
        resizableGhost="true"
        resizableHandles="all"
    >
        <sjg:gridColumn name="id" index="id" title="ID" width="30" formatter="integer" sortable="false"/>
        <sjg:gridColumn name="name" index="name" title="Name" width="250" sortable="true"/>
        <sjg:gridColumn name="country" index="country" title="Country" sortable="false"/>
        <sjg:gridColumn name="city" index="city" title="City" sortable="false"/>
        <sjg:gridColumn name="creditLimit" index="creditLimit" title="Credit Limit" align="right" formatter="currency" sortable="false"/>
    </sjg:grid>
  </div>


请问,您知道如何显示父亲和母亲的ID(我数据库中的外键)吗?此外,是否可以不提及所有属性??非常感谢。

如果我的想法正确,您希望显示
父属性的
Id
母属性的
Id
。这意味着
Person
对象具有
Id
属性。如果这是正确的,你可以这样做

<sjg:gridColumn name="father.id" index="father.id" title="Father Id" width="250" sortable="true"/>
<sjg:gridColumn name="mother.id" index="mother.id" title="Mother Id" width="250" sortable="true"/>


我认为这将解决您的问题。

寻找使用struts2 json插件的示例,特别是include和exclude参数。尽管您应该尽量获取接近您需要的内容,因为从db带回的内容可能比需要的多,这可能会很昂贵。服务层应该指定可以检索的内容。因此,有两个问题:1)如何从数据库中获取所需内容并表示它(服务层与数据库层相结合)和2)数据的表示(使用struts2 json结果)。我不喜欢struts2 jquery标记,因为它们隐藏了细节,从而减少了来自jquery社区的帮助。