0

我对 Java 和一般的递归函数真的很陌生。我对几件事有点迷茫。为什么由于某种原因我得到重复的输出。似乎只有当我遍历内容时。我知道为什么会发生这种情况,因为我的“isPageParent”函数似乎返回 false 并多次运行该函数。但我想不通为什么?我一直在这上面花了几个小时,而且完全卡住了。我是新手,非常感谢代码示例。

public static String generateTest(Page page, Page rootPage, String bc) {

Page parent = page.getParent();

String bread = ""; 
bread += (parent != null) ? "<li><a href=" + parent.getPath() + ">" + parent.getTitle() + "</a>" : "";
bread += "<li>" + "<a href=" + page.getPath() + ">" + page.getTitle() + "</a></li>" + bc;
return (ifPageRoot(parent , rootPage)) ? breadcrumb : generateTest(parent, rootPage, bread);

}

public static boolean ifPageRoot(Page page, Page root) {
return (page == null || root.getPath().equals(page.getPath()));
}

谢谢!

4

0 回答 0