问候:
我在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)
这不起作用,在循环运行时生成堆栈溢出.关于如何做到这一点的任何想法?