Online book marketplace 2 -- Category module, mall 2 -- category

Source: Internet
Author: User

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>

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.