The examples in this article share the Category module code of the Java Online Book Mall for your reference. The specific content is as follows
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 first-level categories*/ 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. Loop through all first-level categories and load its second-level categories for each first-level category*/ for(Category parent : parents) { // Query all child categories of the current parent class List<Category> children = findByParent(parent.getCid()); // Set to the parent class parent.setChildren(children); } return parents;}left.jsp
Q6MenuBar component displays accordion-style 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>The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.