This example for you to share the Java Online Book Mall category module code for your reference, the specific contents are as follows
Sql
CREATE TABLE ' t_category ' (
' CID ' char (m) not NULL,
' CNAME ' varchar ' default NULL,
' pid ' char (#) Default NULL,
' desc ' varchar DEFAULT null,
' by ' int (one) not null auto_increment,
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 levels of classification */
String sql = "Select * FR" Om t_category where PID is null order BY-order;
list<map<string,object>> maplist = qr.query (sql, New Maplisthandler ());
list<category> parents = tocategorylist (maplist);
* * 2. Iterate through all the first-level categories, load it's level two classification for each level of classification * * for
(Category parent:parents) {
//query 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 pull-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>
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.