Java 在Liferay搜索容器中显示来自不同数据库表的数据:Liferay
我一直在使用liferay中的搜索容器来显示表中的数据。效果很好!! 下面是一段代码:Java 在Liferay搜索容器中显示来自不同数据库表的数据:Liferay,java,database,liferay,liferay-6,Java,Database,Liferay,Liferay 6,我一直在使用liferay中的搜索容器来显示表中的数据。效果很好!! 下面是一段代码: <% List<testapp> pendingApprovals = ActionClass.getPendingLeaveApplications(); %> <liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found"> <liferay-ui:search
<%
List<testapp> pendingApprovals = ActionClass.getPendingLeaveApplications();
%>
<liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found">
<liferay-ui:search-container-results total="<%= pendingApprovals.size() %>"
results="<%= ListUtil.subList(pendingApprovals , searchContainer.getStart(), searchContainer.getEnd()) %>" />
<liferay-ui:search-container-row keyProperty = "empId" modelVar="search"
className="com.test.mis.portal.model.testapp">
<liferay-ui:search-container-column-text name='Leave Duration' value = '<%=String.valueOf(search.getLeaveDuration())%>' href="" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator/>
</liferay-ui:search-container>
使用上述代码,我根据某些条件显示testapp表中的数据。
在相同的代码中,我想添加一行并显示数据。此行的数据应来自另一个表。简而言之,我想使用搜索容器显示来自两个不同数据库表的数据。
有可能吗?我的要求是数据来自两个不同的表
有要求的编辑部分
我有一些字段的Employee表
我还有一张桌子,还有一些字段。
empId位于映射到Employee表的Leave表中
我有一个搜索容器,仅当休假待定时才显示休假表中的数据
我只想显示员工表中与休假表匹配并满足上述条件的字段。可能有很多方法,在这里我列出了一些我想到的方法:
TestAppImpl
模型,以包含您的依赖项,如下所示:
公共类TestAppImpl扩展了TestAppBaseImpl{
私有列表otherTableDataList;
私有OtherTableData OtherTableData;
//如果要检索行列表
公共列表getOtherTableDataList(){
//调用在OtherTableDataLocalService中创建的自定义方法
//testAppId变量可用于TestAppImpl
List otherDataList=OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(testAppId);
返回其他数据列表;
}
//如果只想检索一行
公共OtherTableData getOtherTableData(){
//调用在OtherTableDataLocalService中创建的自定义方法
//testAppId变量可用于TestAppImpl
OtherTableData otherData=OtherTableDataLocalServiceUtil.GetOtherDataByteStatAppId(testAppId);
返回其他数据;
}
}
在进行上述更改后,您必须重建服务
现在在JSP中,您可以使用:
<liferay-ui:search-container-column-text name='Other table data name' value='<%=search.getOtherTableData().getName() %>' href="" />
在other_data.jsp
中,我们可以得到以下代码:
<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
TestApp search = (TestApp) row.getObject();
List<OtherTableData> otherDataList = OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(search.getTestAppId());
for (OtherTableData tempData : otherDataList) {
%>
<%=tempData.getName() %>
<%=tempData.getDescription() %>
<%=tempData.getData() %>
<%
}
%>
希望这就是你一直在寻找的东西,否则至少会给你一个前进的提示。可能有很多方法,这里我列出了一些我脑海中浮现的方法:
TestAppImpl
模型,以包含您的依赖项,如下所示:
公共类TestAppImpl扩展了TestAppBaseImpl{
私有列表otherTableDataList;
私有OtherTableData OtherTableData;
//如果要检索行列表
公共列表getOtherTableDataList(){
//调用在OtherTableDataLocalService中创建的自定义方法
//testAppId变量可用于TestAppImpl
List otherDataList=OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(testAppId);
返回其他数据列表;
}
//如果只想检索一行
公共OtherTableData getOtherTableData(){
//调用在OtherTableDataLocalService中创建的自定义方法
//testAppId变量可用于TestAppImpl
OtherTableData otherData=OtherTableDataLocalServiceUtil.GetOtherDataByteStatAppId(testAppId);
返回其他数据;
}
}
在进行上述更改后,您必须重建服务
现在在JSP中,您可以使用:
<liferay-ui:search-container-column-text name='Other table data name' value='<%=search.getOtherTableData().getName() %>' href="" />
在other_data.jsp
中,我们可以得到以下代码:
<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
TestApp search = (TestApp) row.getObject();
List<OtherTableData> otherDataList = OtherTableDataLocalServiceUtil.getOtherDataListByTestAppId(search.getTestAppId());
for (OtherTableData tempData : otherDataList) {
%>
<%=tempData.getName() %>
<%=tempData.getDescription() %>
<%=tempData.getData() %>
<%
}
%>
希望这就是你想要的,否则至少会给你一个前进的提示。你的问题有两个方面:
b) 创建一个自定义类(比如EmployeePendingLeaves),并将其用作searchContainer的模型类。不要将其包含在数据库模型中。只需创建一个函数来扫描Employee和Leave表,并为每个结果行创建EmployeePendingLeaves实例。行的每一列都应该有一个变量/属性这里的问题有两个方面: