如何在jsp上显示递归数据?

时间:2016-01-22 05:46:46

标签: java jsp spring-mvc

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>

现在它正在显示     enter image description here

1 个答案:

答案 0 :(得分:0)

不是每次递送都显示数据,而是构建一个String。我会将StringBuilder传递给递归函数,然后编写一个调用该函数的getStuff()方法,并返回该字符串。 JSP只是引用getStuff()方法。