Wangshu mall 2 -- Category module, mall 2 -- category
SQL
CREATE TABLE `t_category` ( `cid` char(32) NOT NULL, `cname` varchar(50) DEFAULT NULL, `pid` char(32) DEFAULT NULL, `desc` varchar(100) DEFAULT NULL, `orderBy` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`cid`), UNIQUE KEY `cname` (`cname`), KEY `FK_t_category_t_category` (`pid`), KEY `orderBy` (`orderBy`), CONSTRAINT `FK_t_category_t_category` FOREIGN KEY (`pid`) REFERENCES `t_category` (`cid`)) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;
Dao
Public List <Category> findAll () throws SQLException {/** 1. query all level-1 classes */String SQL = "select * from t_category where pid is null order by orderBy"; List <Map <String, Object> mapList = qr. query (SQL, new MapListHandler (); List <Category> parents = toCategoryList (mapList);/** 2. cyclically traverse all level-1 Categories and load their level-2 categories for each level-1 Category */for (Category parent: parents) {// query the List of all subcategories of the current parent Category <Category> children = findByParent (parent. getCid (); // set to parent category parent. setChildren (children);} return parents ;}
Left. jsp
Q6MenuBar component display accordion drop-down menu
<script language="javascript">$(function() {....<c:forEach items="${parents}" var="parent"> <c:forEach items="${parent.children}" var="child">bar.add("${parent.cname}", "${child.cname}", "/goods/BookServlet?method=findByCategory&cid=${child.cid}", "body"); </c:forEach></c:forEach>});</script>