本文實(shí)例為大家分享了java網(wǎng)上圖書商城Category模塊代碼,供大家參考,具體內(nèi)容如下
sql
1
2
3
4
5
6
7
8
9
10
11
12
|
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public List<Category> findAll() throws SQLException { /* * 1. 查詢出所有一級(jí)分類 */ 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. 循環(huán)遍歷所有的一級(jí)分類,為每個(gè)一級(jí)分類加載它的二級(jí)分類 */ for (Category parent : parents) { // 查詢出當(dāng)前父分類的所有子分類 List<Category> children = findByParent(parent.getCid()); // 設(shè)置給父分類 parent.setChildren(children); } return parents; } |
left.jsp
Q6MenuBar組件顯示手風(fēng)琴式下拉菜單
1
2
3
4
5
6
7
8
9
10
11
|
<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> |
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。