[英]How to display recursive data on jsp?
List<TextualReq> textualReqList = session.createQuery("from TextualReq where parent is null").list();
for(TextualReq root : textualReqList){
logger.info("textualReqList ::"+root.getId());
logger.info("textualReqList ::"+root.getData());
logger.info("textualReqList ::"+root.getParent());
logger.info("textualReqList ::"+root.getChildren());
root.display( " " );
}
public void display( String margin )
{
System.out.println( "================="+margin + data );
for ( TextualReq child : children )
{
child.display( margin + " " );
}
}
在Java中此功能將以以下格式打印數據。 我想在jsp頁面中顯示此數據。 可以幫助我如何將這些數據發布到UI並以遞歸方式顯示。 在這里root.getChildren()再次是私有的Set children = new HashSet();
MyRootData
MyChild1Data
MyGrandchild11Data
MyGrandchild12Data
MyGreatGrandchild121Data
MyGrandchild13Data
MyChild2Data
MyGrandchild21Data
MyGrandchild22Data
MyRootData
MyChild1Data
MyGrandchild11Data
MyGrandchild12Data
MyGreatGrandchild121Data
MyGrandchild13Data
MyChild2Data
MyGrandchild21Data
MyGrandchild22Data
我擁有的Jsp代碼是
<h3>TextualReq List</h3>
<c:if test="${!empty listtextualReq}">
<table class="tg">
<tr>
<th width="80">textualReq ID</th>
<!-- <th width="120">textualReq parent</th> -->
<!-- <th width="120">textualReq children</th> -->
<th width="120">textualReq data</th>
<th width="60">Edit</th>
<th width="60">Delete</th>
</tr>
<c:forEach items="${listtextualReq}" var="textualReq">
<tr>
<td>${textualReq.id}</td>
<%-- <td>${textualReq.parent}</td> --%>
<%-- <td>${textualReq.children}</td> --%>
<td>${textualReq.data}</td>
<td><a href="<c:url value='/edittextualReq/${textualReq.id}' />" >Edit</a></td>
<td><a href="<c:url value='/removetextualReq/${textualReq.id}' />" >Delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
而不是每次遞歸都顯示數據,而是構建一個String。 我將StringBuilder傳遞到遞歸函數中,然后編寫一個調用該函數的getStuff()方法,並返回字符串。 JSP將僅引用getStuff()方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.