当前位置:主页 > 软件编程 > JAVA代码 >

java网上图书商城(2)Category模块

时间:2020-10-02 10:19:13 | 栏目:JAVA代码 | 点击:

本文实例为大家分享了java网上图书商城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. 查询出所有一级分类
  */
 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. 循环遍历所有的一级分类,为每个一级分类加载它的二级分类
  */
 for(Category parent : parents) {
  // 查询出当前父分类的所有子分类
  List<Category> children = findByParent(parent.getCid());
  // 设置给父分类
  parent.setChildren(children);
 }
 return parents;
}

left.jsp

Q6MenuBar组件显示手风琴式下拉菜单

<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>

您可能感兴趣的文章:

相关文章