Sql
CREATE TABLE ' t_category ' ( ' cid ' char (+) NOT NULL, ' CNAME ' varchar () default NULL, ' pid ' char (+) ' Default ' NULL, ' desc ' varchar (+) DEFAULT null, ' auto_increment ' int (one) not NULL, PRIMARY KEY (' CID '), UNIQUE KEY ' cname ' (' cname '), Key ' Fk_t_category_t_category ' (' pid '), key ' by ' (' by ') ', ' 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 out all first-level classifications */string sql = "SELECT * FROM T_category wher E PID is a null order by "; list<map<string,object>> maplist = qr.query (sql, New Maplisthandler ()); list<category> parents = tocategorylist (maplist);/* * 2. Loops through all of the first-level classifications, loading its level two category */for (category parent:parents) {//querying out all subcategories of the current parent category list<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>
Online Book Mall 2--category module