Struts1.2+Hibernate3.0+JavaScript+JSTL1.1 实现无限级树形菜单
一、说明:
1、开发环境:
Eclipse3.2.1+MyEclipse5.1+Tomcat5.5+Microsoft SQL Server 2000
2、主要实现技术:Struts1.2+Hibernate3.0+JavaScript+JSTL1.1+自定义标签
3、页面的树形菜单的节点用 JavaScript进行控制
4、数据库中的商品类别表productCategory包含一个引用自身主键的外键,从而形成自身一对多关系
5、自定义标签实现类Recursion中主要用了递归实现节点的展开
二、完成后运行效果如下图:
三、具体实现步骤:
1、新建一个Web Project工程(随便加载JSTL1.1的支持),创建如下图所示的结构目录;
2、创建数据库
数据库中就只有两张表,其中商品类别?商品为一对多关系,商品类别自身形成一对多关系(引用主键:类别编号做外键:父类编号),下面是由PowerDesigner 12 画的概念图
生成的数据库脚本tree.sql如下:
/*==============================================================*/ /* DBMS name: Microsoft SQL Server 2000 */ /* Created on: 2007-07-14 09:10:40 */
/*==============================================================*/
/*==============================================================*/ /* Table: product */
/*==============================================================*/ create database tree go
use tree go
create table product (
productId int identity not null, CategoryId int not null, productName varchar(100) not null, productPrice money not null,
constraint PK_PRODUCT primary key nonclustered (productId) ) go
/*==============================================================*/ /* Index: ProductCategoryToProduct_FK */
/*==============================================================*/ create index ProductCategoryToProduct_FK on product ( CategoryId ASC ) go
/*==============================================================*/ /* Table: productCategory */
/*==============================================================*/ create table productCategory (
CategoryId int identity not null, ParentCategoryId int null,
CategoryName varchar(50) not null,
constraint PK_PRODUCTCATEGORY primary key nonclustered (CategoryId) ) go
/*==============================================================*/ /* Index: 商品类别拥有商品类别_FK */ /*==============================================================*/ create index 商品类别拥有商品类别_FK on productCategory ( ParentCategoryId ASC ) go
alter table product
add constraint FK_PRODUCT_PRODUCTCA_PRODUCTC foreign key (CategoryId) references productCategory (CategoryId) go
alter table productCategory
add constraint FK_PRODUCTC_商品类别拥有商品类_PRODUCTC foreign key (ParentCategoryId)
references productCategory (CategoryId)
用查询分析器运行上述脚本,在数据库中建
表product结构如下图:
表productCategory结构如下图:
3、数据库建好后,通过MyEclipse加载Struts 1.2、Hibernate 3.0的支持