我使用Struts 2.3.7, struts2-jquery-grid-plugin-3.5.0和hibernate 3.6。我想显示jqgrid
上的数据,它来自两个不同的表。
我的问题是我必须在一个jqgrid
中显示两个表数据。前三个jqgrid
列由Issue
表填充,最后一列name="assignedTo"
由Issue_Tracker
表填充。如何显示最后一列即assignedTo
中的数据。如有任何帮助,我将不胜感激。
My jqgrid is
<sjg:grid
id="gridtable"
caption="Issue-Summary"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
rowList="10,15,20"
rowNum="15"
rownumbers="true"
reloadTopics="reloadGrid"
>
<sjg:gridColumn name="issue_id" id="issueId" index="id" title="Issue-ID" formatter="integer" sortable="false"/>
<sjg:gridColumn name="issue_description" index="id" title="Issue-Details" sortable="false"/>
<sjg:gridColumn name="issue_raised_date" index="date" title="Issue-Date" formatter="date" sortable="false"/>
<sjg:gridColumn name="assignedTo" index="assigned" title="Assigned To" sortable="false"/>
</sjg:grid>
我有pojo's:
Issue.java
public class Issue implements Serializable
{
private Integer issue_id;
private String issue_description;
private Date issue_raised_date;
getters and setters
另一个pojo是
Issue_Tracker.java
public class Issue_Tracker implements Serializable
{
private Integer issue_id;
private String assignedTo;
jqgrid和My Dao中的问题列表如下所示public List<Issue> showHelpDeskIssues(DetachedCriteria dc, int from, int size)
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try
{
Criteria criteria = dc.getExecutableCriteria(session);
criteria.setFirstResult(from);
criteria.setMaxResults(size);
criteria.add(Restrictions.eq("status","Escalate To"));
return criteria.list();
}
catch (HibernateException e)
{
e.printStackTrace();
throw e;
}
}
您可以像这样为pojo中的另一个pojo创建一个集合
public class Issue implements Serializable
{
private Integer issue_id;
private String issue_description;
private Date issue_raised_date;
private Set<Issue_Tracker> issue_Tracker;
public Set<Issue_Tracker> getIssue_Tracker() {
return issue_Tracker;
}
public void setIssue_Tracker(Set<Issue_Tracker> issue_Tracker) {
this.sidUserSites = issue_Tracker;
}
}
现在你可以通过Issue pojo访问Issue_Tracker pojo。您需要使用连接查询
你可以用两个表的组合列在DB中创建视图。为该视图创建PoJo和Mapping类并轻松执行!