Java 使用递归和 JSTL 在 jsp 上显示树结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18436831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display tree structure on a jsp using Recursion and JSTL
提问by edaklij
I would like to implement a tree structure in my JSP baised web-application using recursion and JSTL.The values of tree is populated from database using java(using some list or map..).I know this question may be asked by some peoples.but i didn't get any idea from those resources.Please help me..
我想使用递归和 JSTL 在我的基于 JSP 的 web 应用程序中实现一个树结构。树的值是使用 java(使用一些列表或地图..)从数据库填充的。我知道这个问题可能会被一些人问到.但我没有从这些资源中得到任何想法。请帮助我..
Here is my Table Structure for company table.
这是我公司表的表结构。
Column Type
Company_id int
Company_parent_id int
Company_name varchar(50)
Class Company
班级公司
public Class Company{
private int companyId;
private int companyParantId;
private String companyName;
//getters&setters
}
Sample tree structure that i watnt to implement.
我想要实现的示例树结构。
1
1.1
1.2
1.2.1
1.2.1.1
2
2.1
3
3.1
3.1.1
.....
n
n.1
....
My question is How can i implement Recursion in jsp with the help of JSTL?.
我的问题是如何在 JSTL 的帮助下在 jsp 中实现递归?
Thanks,
谢谢,
采纳答案by orasca
You may want to look at Displaying tree on JSP pagepost.
There is good discussion about how to achieve it manually (using jsp recursion) and also a good list of third-party utilities that can easily do it for you.
关于如何手动实现它(使用 jsp 递归)有很好的讨论,还有一个很好的第三方实用程序列表,可以轻松地为您完成。
回答by Scary Wombat
I have recently implemented a very similar structure. Simply by building the list and recording the parent id, it is possible using Jquery and the jquery.treeTable.js plugin to display this hierarchy as a tree with expandable/collapsible nodes.
我最近实现了一个非常相似的结构。只需构建列表并记录父 ID,就可以使用 Jquery 和 jquery.treeTable.js 插件将此层次结构显示为具有可展开/可折叠节点的树。
Not exactly what you asked, but as you know coding in JSP is frowned upon, this is rather a good way I feel.
不完全是你问的,但正如你所知,在 JSP 中编码是不受欢迎的,我觉得这是一种很好的方式。