Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> 網上商城4--首頁二級分類的查詢,4--二級分類

網上商城4--首頁二級分類的查詢,4--二級分類

編輯:關於android開發

網上商城4--首頁二級分類的查詢,4--二級分類


 

1.創建表

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', '潮流女裝', '1');
INSERT INTO `categorysecond` VALUES ('2', '初冬羽絨', '1');
INSERT INTO `categorysecond` VALUES ('3', '毛呢大衣', '1');
INSERT INTO `categorysecond` VALUES ('4', '溫暖毛衣', '1');
INSERT INTO `categorysecond` VALUES ('5', '精選男裝', '1');
INSERT INTO `categorysecond` VALUES ('6', '冬季外套', '1');
INSERT INTO `categorysecond` VALUES ('7', '羽絨服', '1');
INSERT INTO `categorysecond` VALUES ('9', '女鞋', '2');
INSERT INTO `categorysecond` VALUES ('10', '短靴', '2');
INSERT INTO `categorysecond` VALUES ('11', '男鞋', '2');
INSERT INTO `categorysecond` VALUES ('12', '女包', '2');
INSERT INTO `categorysecond` VALUES ('13', '男包', '2');
INSERT INTO `categorysecond` VALUES ('14', '服飾配件', '2');
INSERT INTO `categorysecond` VALUES ('15', '運動鞋', '3');
INSERT INTO `categorysecond` VALUES ('16', '運動服', '3');
INSERT INTO `categorysecond` VALUES ('17', '戶外運動', '3');
INSERT INTO `categorysecond` VALUES ('18', '健身裝備', '3');
INSERT INTO `categorysecond` VALUES ('19', '騎行裝備', '3');
INSERT INTO `categorysecond` VALUES ('20', '珠寶首飾', '4');
INSERT INTO `categorysecond` VALUES ('21', '時尚飾品', '4');
INSERT INTO `categorysecond` VALUES ('22', '品質手表', '4');
INSERT INTO `categorysecond` VALUES ('23', '眼鏡配飾', '4');
INSERT INTO `categorysecond` VALUES ('24', '手機', '5');
INSERT INTO `categorysecond` VALUES ('25', '平板', '5');
INSERT INTO `categorysecond` VALUES ('26', '電腦', '5');
INSERT INTO `categorysecond` VALUES ('27', '相機', '5');
INSERT INTO `categorysecond` VALUES ('28', '大家電', '6');
INSERT INTO `categorysecond` VALUES ('29', '廚房電器', '6');
INSERT INTO `categorysecond` VALUES ('30', '生活電器', '6');
INSERT INTO `categorysecond` VALUES ('31', '個戶電器', '6');
INSERT INTO `categorysecond` VALUES ('32', '辦公耗材', '6');
INSERT INTO `categorysecond` VALUES ('33', '美容護膚', '7');
INSERT INTO `categorysecond` VALUES ('34', '強效保養', '7');
INSERT INTO `categorysecond` VALUES ('35', '超值彩妝', '7');
INSERT INTO `categorysecond` VALUES ('36', '換季保養', '7');

 

2.一級分類下二級分類

<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">
<hibernate-mapping>
	<class name="cn.itcast.shop.category.vo.Category" table="category">
		<id name="cid" column="cid">
			<generator class="native"></generator>
		</id>
		
		<property name="cname" column="cname"/>
		
		<set name="categorySeconds" order-by="csid" fetch="join" lazy="false" cascade="delete">
			<key column="cid"/>
			<one-to-many class="cn.itcast.shop.categorysecond.vo.CategorySecond"/>
		</set>
	</class>
</hibernate-mapping>

  

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved