15.首页查询一级分类商品列出左侧分类信息

首页上点击一级分类跳转到商品列表页面,左侧显示一级分类与二级分类信息。

1、在menu.jsp上添加action,传递一级分类cid。

<li><a href="${pageContext.request.contextPath }/product_findByCid?cid=<s:property value="#c.cid"/>"><s:property value="#c.cname"/></a>|</li>

2、创建二级分类的包及类

* cn.itcast.shop.categorysecond

* action

* CategoryAction

* service

* CategoryService

* dao

* CategoryDao

* vo

* CategorySecond

* CategorySecond.hbm.xml

3、配置一级分类和二级分类的关联关系

CategorySecond.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.xdy.shop.categorySecond.vo.CategorySecond" table="categorysecond">
		<id name="csid">
			<generator class="native"/>
		</id>

		<property name="csname"/>

		<many-to-one name="category" class="cn.xdy.shop.category.vo.Category" column="cid"/>
	</class>
</hibernate-mapping>

CategorySecond.java

package cn.xdy.shop.categorySecond.vo;

import cn.xdy.shop.category.vo.Category;

public class CategorySecond {

	private String csid;
	private String csname;
	private Category category;
	public String getCsid() {
		return csid;
	}
	public void setCsid(String csid) {
		this.csid = csid;
	}
	public String getCsname() {
		return csname;
	}
	public void setCsname(String csname) {
		this.csname = csname;
	}
	public Category getCategory() {
		return category;
	}
	public void setCategory(Category category) {
		this.category = category;
	}

}

Category.hbm.xml中加入CategorySecond的信息

		<set name="categorySeconds" lazy="false" order-by="cid">
			<key column="cid"/>
			<one-to-many class="cn.xdy.shop.categorySecond.vo.CategorySecond"/>
		</set>

Category.java中加入二级分类信息

private Set<CategorySecond> categorySeconds = new HashSet<CategorySecond>();

	public Set<CategorySecond> getCategorySeconds() {
		return categorySeconds;
	}

	public void setCategorySeconds(Set<CategorySecond> categorySeconds) {
		this.categorySeconds = categorySeconds;
	}

4、编写Action中方法findByCid,因session中有分类信息,所以页面上直接从session中取即可。

/**
	 * 根据分类ID查询所有
	 * @return
	 */

	public String findByCid(){
		//因为IndexAction中查询了一级分类存入session中,所以此处不再查询,页面上直接从session中取即可。
		return "findByCid";
	}

5、Struts.xml中配置findByCid

<!-- 商品action -->
    	<action name="product_*" class="productAction" method="{1}">
    		<result name="findByPid">/WEB-INF/jsp/product.jsp</result>
    		<result name="findByCid">/WEB-INF/jsp/productList.jsp</result>
    	</action>

6、编写productList.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0048)http://localhost:8080/mango/product/list/1.jhtml -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>星辰网上商城</title>
<link href="${pageContext.request.contextPath}/css/common.css" rel="stylesheet" type="text/css"/>
<link href="${pageContext.request.contextPath}/css/product.css" rel="stylesheet" type="text/css"/>

</head>
<body>
<div class="container header">
	<div class="span5">
		<div class="logo">
			<a href="http://localhost:8080/mango/">
				<img src="${pageContext.request.contextPath}/image/r___________renleipic_01/logo.gif" alt="星辰商城">
			</a>
		</div>
	</div>
	<div class="span9">
<div class="headerAd">
					<img src="${pageContext.request.contextPath}/image/header.jpg" width="320" height="50" alt="正品保障" title="正品保障">
</div>	</div>

	<%@include file="menu.jsp" %>
</div>
<div class="container productList">
		<div class="span6">
			<div class="hotProductCategory">
				<s:iterator var="c" value="#session.cList">
						<dl>
							<dt>
								<a href="${pageContext.request.contextPath}/image/蔬菜 - Powered By Mango Team.htm"><s:property value="#c.cname"/></a>
							</dt>
								<s:iterator var="cs" value="#c.categorySeconds">
									<dd>
										<a ><s:property value="#cs.csname"/></a>
									</dd>
								</s:iterator>
						</dl>
				</s:iterator>
			</div>
		</div>
		<div class="span18 last">

			<form id="productForm" action="${pageContext.request.contextPath}/image/蔬菜 - Powered By Mango Team.htm" method="get">
				<input type="hidden" id="brandId" name="brandId" value="">
				<input type="hidden" id="promotionId" name="promotionId" value="">
				<input type="hidden" id="orderType" name="orderType" value="">
				<input type="hidden" id="pageNumber" name="pageNumber" value="1">
				<input type="hidden" id="pageSize" name="pageSize" value="20">

				<div id="result" class="result table clearfix">
						<ul>
						<li>
										<a href="./京华商城分页面.htm">
											<img src="${pageContext.request.contextPath}/image/4a51167a-89d5-4710-aca2-7c76edc355b8-thumbnail.jpg" width="170" height="170"  style="display: inline-block;">

											<span style='color:green'>
											 大冬瓜
											</span>

											<span class="price">
												商城价: ¥4.78/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/0ff130db-0a1b-4b8d-a918-ed9016317009-thumbnail.jpg" width="170" height="170" " style="display: inline-block;">
											<span style='color:green'>
											   圆白菜
											</span>
											<span class="price">
												商城价: ¥1.78/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/f5e39c37-94b2-462e-8e58-8bde3c5f1b8c-thumbnail.jpg" width="170" height="170"   style="display: inline-block;">
											<span style='color:green'>
											   甜玉米
											</span>
											<span class="price">
												商城价: ¥4.48/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/f37ba36a-181b-4161-a88f-f74c9adb485d-thumbnail.jpg" width="170" height="170"   style="display: inline-block;">
											<span style='color:green'>
											   胡萝卜
											</span>
											<span class="price">
												商城价: ¥1.58/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/93b9e55f-cbae-4c3c-b2f7-2636c7369db7-thumbnail.jpg" width="170" height="170"  style="display: inline-block;">
											<span style='color:green'>
											   芹菜
											</span>
											<span class="price">
												商城价: ¥2.18/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/51afeef5-f6cb-4936-abea-315cfca0edc0-thumbnail.jpg" width="170" height="170"  style="display: inline-block;">
											<span style='color:green'>
											   小西红柿
											</span>
											<span class="price">
												商城价: ¥6.98/份
											</span>

										</a>
									</li>
									<li>
										<a>
											<img src="${pageContext.request.contextPath}/image/059b5245-e3c8-43bf-80fe-700f0e4e68b8-thumbnail.jpg" width="170" height="170"  style="display: inline-block;">
											<span style='color:green'>
											   白萝卜
											</span>
											<span class="price">
												商城价: ¥3.98/份
											</span>

										</a>
									</li>

									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/750a9ce8-8c19-444d-b8cc-f3e7e786ec5d-thumbnail.jpg" width="170" height="170"  style="display: inline-block;">
											<span style='color:green'>
											   菠菜
											</span>
											<span class="price">
												商城价: ¥3.48/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPic372e7faa-3ad0-444d-a89b-a8e9f0d6e929.jpg" width="170" height="170"  >
											<span style='color:green'>
											   香菜
											</span>
											<span class="price">
												商城价: ¥2.98/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPica7e5d3dd-5984-4d0f-9851-35cc0987d9b9.jpg" width="170" height="170" >
											<span style='color:green'>
											   白菜花
											</span>
											<span class="price">
												商城价: ¥5.38/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPica5720219-ba48-460a-a084-24d5b314bd03.jpg" width="170" height="170"  >
											<span style='color:green'>
											   韭菜
											</span>
											<span class="price">
												商城价: ¥2.38/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPicaa443d05-27b4-4964-958e-c81536f01d04.jpg" width="170" height="170"  >
											<span style='color:green'>
											   土豆
											</span>
											<span class="price">
												商城价: ¥2.48/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPicc1e3a29e-17f5-4d9f-a186-b2c5a0b39b88.jpg" width="170" height="170" >
											<span style='color:green'>
											   黄瓜
											</span>
											<span class="price">
												商城价: ¥2.58/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPicd0459632-fe4e-4a5d-8373-1a67c9f43ec2.jpg" width="170" height="170" >
											<span style='color:green'>
											   西红柿
											</span>
											<span class="price">
												商城价: ¥2.58/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPice7c2e240-4147-4c11-b369-db3765ec3df9.jpg" width="170" height="170"  >
											<span style='color:green'>
											   大白菜
											</span>
											<span class="price">
												商城价: ¥8.78/份
											</span>

										</a>
									</li>
									<li>
										<a >
											<img src="${pageContext.request.contextPath}/image/54890cf9-91b0-40bc-9f68-51462e9c43a8.jpg" width="170" height="170"  >
											<span style='color:green'>
											   紫甘蓝
											</span>
											<span class="price">
												商城价: ¥5.98/份
											</span>

										</a>
									</li>
									<li class="last">
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPic4ed6edbf-fb3e-49a7-be5e-361b2ce02961.jpg" width="170" height="170" >
											<span style='color:green'>
											   荷兰豆
											</span>
											<span class="price">
												商城价: ¥9.28/份
											</span>

										</a>
									</li>
									<li class="last">
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPic5ab54f67-a479-48fe-a41d-7d34b57036a3.jpg" width="170" height="170" >
											<span style='color:green'>
											   尖椒
											</span>
											<span class="price">
												商城价: ¥2.48/份
											</span>

										</a>
									</li>
									<li class="last">
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPic13867cc1-935a-4a3a-98f9-edf87ddb1c09.jpg" width="170" height="170" >
											<span style='color:green'>
											   小香葱
											</span>
											<span class="price">
												商城价: ¥2.98/份
											</span>

										</a>
									</li>
									<li class="last">
										<a >
											<img src="${pageContext.request.contextPath}/image/bigPicee0785e3-68e2-4e23-93ef-68904bc2a3c6.jpg" width="170" height="170" >
											<span style='color:green'>
											  圆茄子
											</span>
											<span class="price">
												商城价: ¥1.58/份
											</span>

										</a>
									</li>
						</ul>
				</div>
	<div class="pagination">
			<span class="firstPage"> </span>
			<span class="previousPage"> </span>
				<span class="currentPage">1</span>
				<a href="javascript: $.pageSkip(2);">2</a>
			<a class="nextPage" href="javascript: $.pageSkip(2);"> </a>

			<a class="lastPage" href="javascript: $.pageSkip(2);"> </a>
	</div>
			</form>
		</div>
	</div>
<div class="container footer">
	<div class="span24">
		<div class="footerAd">
					<img src="${pageContext.request.contextPath}/image/footer.jpg" width="950" height="52" alt="我们的优势" title="我们的优势">
</div>	</div>
	<div class="span24">
		<ul class="bottomNav">
					<li>
						<a >关于我们</a>
						|
					</li>
					<li>
						<a>联系我们</a>
						|
					</li>
					<li>
						<a >诚聘英才</a>
						|
					</li>
					<li>
						<a >法律声明</a>
						|
					</li>
					<li>
						<a>友情链接</a>
						|
					</li>
					<li>
						<a target="_blank">支付方式</a>
						|
					</li>
					<li>
						<a  target="_blank">配送方式</a>
						|
					</li>
					<li>
						<a >官网</a>
						|
					</li>
					<li>
						<a >论坛</a>

					</li>
		</ul>
	</div>
	<div class="span24">
		<div class="copyright">Copyright©2005-2015 网上商城 版权所有</div>
	</div>
</div>
</body></html>
时间: 2025-01-09 19:30:40

15.首页查询一级分类商品列出左侧分类信息的相关文章

wordpress在首页列出所有分类及分类下的文章

前面我们谈了wordpress调用指定分类文章,如果想要调用所有分类的文章如何实现呢?比如在wordpress首页列出所有分类及分类下的文章,其实方法类似 <?php $cats = get_categories(); foreach ( $cats as $cat ) { query_posts( 'showposts=10&cat=' . $cat->cat_ID ); ?> <h3><?php echo $cat->cat_name; ?>&l

ThinkPHP分类查询(获取当前分类的子分类,获取父分类,下一级分类)

获取指定分类的所有子分类ID号 //获取指定分类的所有子分类ID号 function getAllChildcateIds($categoryID){ //初始化ID数组 $array[] = $categoryID; do { $ids = ''; $where['pid'] = array('in',$categoryID); $cate = M('cate')->where($where)->select(); foreach ($cate as $k=>$v){ $array[]

根据一个分类id 获取这个分类底下所有子分类的商品信息,根据下面方法查询出所有有关分类id 再 根据这些id去商品表里查询所有商品信息

/** * 检测该分类下所有子分类,并输出ID(包括自己) * 数据库字段 catid pid */ function getChildrenIds ($sort_id){ include_once APPPATH.'/libraries/db.php'; $db = new Db(); $ids = $sort_id; $sql = "SELECT catid,pid FROM jy_category WHERE pid =".$sort_id; $result = $db->

【JAVAWEB学习笔记】网上商城实战2:异步加载分类、Redis缓存分类和显示商品

网上商城实战2 今日任务 完成分类模块的功能 完成商品模块的功能 1.1      分类模块的功能: 1.1.1    查询分类的功能: 1.1.2    查询分类的代码实现: 1.1.2.1  创建表: CREATE TABLE `category` ( `cid` varchar(32) NOT NULL, `cname` varchar(20) DEFAULT NULL, PRIMARY KEY (`cid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 1

商城左侧分类jquery菜单

jquery,左侧分类,商城分类,导航菜单,商城左侧分类jquery导航菜单特效是一款实用性非常大的特效,是商城必不可少的神兵利器.huiyi8素材网. 源于:http://www.huiyi8.com/daohang/

【SSH网上商城项目实战11】查询和删除商品功能的实现

在第8节我们完成了查询和删除商品类别的功能,那么现在实现查询和删除商品的功能就很好做了,原理和第8节一模一样,只是修改一些参数,比如请求不同的action等.由于查询和删除商品不需要弹出新的UI窗口,所以我们只要完成完成query.jsp中相应的部分以及相应的后台即可. 1. 查询商品功能的实现 查询功能主要在查询框中实现,从上一节可知,查询框用的是一个text:"<input id='ss' name='serach' />",我们通过把普通的文本框转化为查询搜索文本框来

ECSHOP在商品详细页面上获取该商品的顶级分类id和名称

在 goods.php 文件, 找到 $smarty->assign('goods', $goods); 在它上面增加下面代码: 方法一: $cat_arr = get_parent_cats($goods['cat_id']); foreach ($cat_arr AS $val) { $goods['topcat_id']=$val['cat_id']; $goods['topcat_name']=$val['cat_name']; } 方法二: $cat_arr = get_parent_

查询个人站点的文章、分类和标签查询

urls.py re_path('^(?P<username>\w+)$', views.home_site, name='home_site'), home_site.py def home_site(request, username): """ 个人站点视图函数 :param request: :return: """ user = UserInfo.objects.filter(username=username).first

商品产品列表分类可右侧展开详细分类DIV+CSS+JS特效(http://www.divcss5.com/css-texiao/texiao746.shtml)

仿京东.当当等大型网站商品分类.产品分类展开菜单,鼠标移动对应分类上右侧展开更详细分类特效,此分类特效采用DIV+CSS+JS实现兼容各大浏览器,可任意更改,简单大方. 商品分类右侧展开更详细特效截图 鼠标放到商品分类上背景变色.加边框,同时右侧对应显示更详细的分类内容.可用于商品分类.产品分类的详细分类展开隐藏. 本分类特效菜单采用DIV CSS布局. 在线演示: