Online mall 4 -- query of the second-level category on the homepage; 4 -- second-level category
1. Create a table
Create table 'categorysecond' ('csid' int (11) not null AUTO_INCREMENT, 'csname' varchar (255) default null, 'cid' int (11) default null, primary key ('csid '), KEY 'fk936fcaf21db1fd15' ('cid'), CONSTRAINT 'fk936fcaf21db1fd15 'foreign key ('cid') REFERENCES 'category' ('cid ')) ENGINE = InnoDB AUTO_INCREMENT = 37 default charset = utf8; insert into 'categorysecond' VALUES ('1', 'trendy Women's upgrade', '1 '); insert into 'categorysecond' VALUES ('2', 'Winter Day', '1'); insert into 'categorysecond' VALUES ('3', 'woolen overcoats ', '1'); insert into 'categorysecond' VALUES ('4', 'warm url', '1'); insert into 'categorysecond' VALUES ('5 ', 'selected men's wear ', '1'); insert into 'categorysecond' VALUES ('6', 'Winter coats', '1 '); insert into 'categorysecond' VALUES ('7', 'undercoats ', '1'); insert into 'categorysecond' VALUES ('9', 'Women shoes', '2 '); insert into 'categorysecond' VALUES ('10', 'Boots ', '2'); insert into 'categorysecond' VALUES ('11', 'Men's shoes', '2 '); insert into 'categorysecond' VALUES ('12', 'female bundle ', '2'); insert into 'categorysecond' VALUES ('13', 'male bundle', '2 '); insert into 'categorysecond' VALUES ('14', 'apparel accessories ', '2'); insert into 'categorysecond' VALUES ('15', 'sneakers ', '3'); insert into 'categorysecond' VALUES ('16', 'track', '3'); insert into 'categorysecond' VALUES ('17 ', 'outdoor sports ', '3'); insert into 'categorysecond' VALUES ('18', 'fitness equipment', '3 '); insert into 'categorysecond' VALUES ('19', 'cycling equiptment ', '3'); insert into 'categorysecond' VALUES ('20', 'Jewelry ', '4'); insert into 'categorysecond' VALUES ('21', 'fashion jewelry ', '4'); insert into 'categorysecond' VALUES ('22 ', 'Quality watch ', '4'); insert into 'categorysecond' VALUES ('23', 'glasses accessory', '4 '); insert into 'categorysecond' VALUES ('24', 'cell phone ', '5'); insert into 'categorysecond' VALUES ('25', 'flat', '5 '); insert into 'categorysecond' VALUES ('26', 'computer ', '5'); insert into 'categorysecond' VALUES ('27', 'camera', '5 '); insert into 'categorysecond' VALUES ('28', 'household appliances ', '6'); insert into 'categorysecond' VALUES ('29', 'kitchen appliances ', '6'); insert into 'categorysecond' VALUES ('30', 'household Electric Appliance ', '6'); insert into 'categorysecond' VALUES ('31 ', 'household appliances ', '6'); insert into 'categorysecond' VALUES ('32', 'Office consumables', '6 '); insert into 'categorysecond' VALUES ('33', 'skin beautifier ', '7'); insert into 'categorysecond' VALUES ('34', 'powerful maintain ', '7'); insert into 'categorysecond' VALUES ('35', 'value-added makeup ', '7'); insert into 'categorysecond' VALUES ('36 ', 'seasonal maintenance ', '7 ');
2. Level 2 classification under Level 1 Classification
<s:iterator var="c" value="#session.cList"><dl><dt><a href="${pageContext.request.contextPath}/product_findByCid.action?cid=<s:property value="#c.cid"/>&page=1"><s:property value="#c.cname"/></a></dt><s:iterator var="cs" value="#c.categorySeconds"><dd><a href="${ pageContext.request.contextPath }/product_findByCsid.action?csid=<s:property value="#cs.csid"/>&page=1"><s:property value="#cs.csname"/></a></dd></s:iterator></dl></s:iterator>
Category. hbm. xml
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">