小编jse*_*als的帖子

如何使用递归获得父母的所有孩子,然后是他们的孩子

问候:

我在JSP Web应用程序中有父事务的比喻.我将事务ID存储在数据库中,并且要求显示父项的所有子项,然后显示父项子项的后续子项.实际上,这个父母及其子女的名单将永远不会超过4或5级,但我需要考虑到它可以比这更多层次.

我试过这样做将递归如下:

private static void processChildrenTransactions(
    AllTremorTransactionsVO parentBean,
    ArrayList<AllTremorTransactionsVO> childCandidatesList )
{
  ArrayList<AllTremorTransactionsVO> childList =
      new ArrayList<AllTremorTransactionsVO>();

  for (AllTremorTransactionsVO childTransactions : childCandidatesList)
  {
    if (childTransactions.getParentGuid() != null)
    {
      if (childTransactions.getParentGuid().equals(parentBean.getTransactionGuid()))
      {
        childList.add(childTransactions);
      }
    }
  }

  for (AllTremorTransactionsVO allTremorTransactionsVO : childList)
  {
    processChildrenTransactions(allTremorTransactionsVO, childList);    
  }

  return;
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,在循环运行时生成堆栈溢出.关于如何做到这一点的任何想法?

java recursion jsp servlets

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

jsp ×1

recursion ×1

servlets ×1