【项目实战】---商品详情页的制作

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

       在前面的博文中,小编分别简单的介绍了邮件的发送以及邮件的**,逛淘宝的小伙伴都有这样的体会,比如在搜索框中输入连衣裙这个商品的时候,会出现多种多样各种款式的连衣裙,连衣裙的信息包括价格,多少人购买,商品的名称等等,但是这些信息不够详情,我们需要了解更多的关于连衣裙的详情,点击某个商品,跳转页面,查看连衣裙的详情,以前小编逛淘宝的时候,从来都没有想过这个功能是如何实现,只知道一个劲儿的在那儿逛,小编现在接手的这个项目中就遇到这样的功能,点击商品跳转到某个商品的详情页面,这个功能该如何实现呢?不要着急,今天这篇博客,小编就简单的向小伙伴们介绍一下,如何点击商品跳转到详情页面,希望对有需求的小伙伴有所帮助,还请小伙伴多多指教哦`(*∩_∩*)′~~~

       首先第一步,我们要找个某个商品的具体链接,传递商品的ID来进行查询,根据商品的ID来显示相对应的商品,我们要修改首页的超链接的路径。接着第二步,我们需要编写Action中的代码,首先编写Action类,继承ActionSupport实现模型驱动接口,具体代码如下所示:

package cn.itcast.shop.product.action;import cn.itcast.shop.product.service.ProductService;import cn.itcast.shop.product.vo.Product;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;/** * 商品的Action对象 * @author Flower * */public class ProductAction extends ActionSupport implements ModelDriven<Product> //用于接收数据的模型驱动 private Product product = new Product(); //注入商品的Service private ProductService productService;  public void setProductService(ProductService productService) {  this.productService = productService; } public Product getModel() {  return product; }  //根据商品的ID进行查询商品:执行方法: public String findByPid(){  //调用Service的方法完成查询  product = productService.findByPid(product.getPid());    return "findByPid";   }}
       第三步,需要配置Action,有两个地方需要进行配置工作,第一个在application.xml中配置Action,代码如下所示:

<!-- 商品模块的Action --> <bean id="productAction" class="cn.itcast.shop.product.action.ProductAction" scope="prototype">  <property name="productService" ref="productService"/> </bean>
       第二个在struts.xml中配置Action;

<!-- 商品模块的Action -->  <action name="product_*" class="productAction" method="{1}">      <result name="findByPid">/WEB-INF/jsp/product.jsp</result>  </action>
       第四步,我们需要在Action中调用service完成根据ID进行查询的方法,注入ProductService的方法,之后就是一些方法的调用,ProductService直接调用ProductDao里面的findByPid的方法,ProductDao直接返回即可。html页面布局代码如下图所示:

<%@ page language="java" contentType="text/html; charset=UTF-8"    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"><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"/><script> function saveCart(){  document.getElementById("cartForm").submit(); }</script></head><body><div class="container header"> <div class="span5">  <div class="logo">   <a>    <img src="${pageContext.request.contextPath}/image/r___________renleipic_01/logo.gif" alt="传智播客">   </a>  </div> </div> <div class="span9"><div class="headerAd">     <img src="image\r___________renleipic_01/header.jpg" alt="正品保障" title="正品保障" height="50" width="320"></div> </div>  <%@ include file="menu.jsp" %></div><div class="container productContent">  <div class="span6">   <div class="hotProductCategory">     <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>    </div>     </div>    <div class="span18 last">      <div class="productImage">     <a title="" style="outline-style: none; text-decoration: none;" id="zoom" href="http://image/r___________renleipic_01/bigPic1ea8f1c9-8b8e-4262-8ca9-690912434692.jpg" rel="gallery">      <div class="zoomPad"><img style="opacity: 1;" title="" class="medium" src="${ pageContext.request.contextPath }/<s:property value="model.image"/>"><div style="display: block; top: 0px; left: 162px; width: 0px; height: 0px; position: absolute; border-width: 1px;" class="zoomPup"></div><div style="position: absolute; z-index: 5001; left: 312px; top: 0px; display: block;" class="zoomWindow"><div style="width: 368px;" class="zoomWrapper"><div style="width: 100%; position: absolute; display: none;" class="zoomWrapperTitle"></div><div style="width: 0%; height: 0px;" class="zoomWrapperImage"><img src="%E5%B0%9A%E9%83%BD%E6%AF%94%E6%8B%89%E5%A5%B3%E8%A3%852013%E5%A4%8F%E8%A3%85%E6%96%B0%E6%AC%BE%E8%95%BE%E4%B8%9D%E8%BF%9E%E8%A1%A3%E8%A3%99%20%E9%9F%A9%E7%89%88%E4%BF%AE%E8%BA%AB%E9%9B%AA%E7%BA%BA%E6%89%93%E5%BA%95%E8%A3%99%E5%AD%90%20%E6%98%A5%E6%AC%BE%20-%20Powered%20By%20Mango%20Team_files/6d53c211-2325-41ed-8696-d8fbceb1c199-large.jpg" style="position: absolute; border: 0px none; display: block; left: -432px; top: 0px;"></div></div></div><div style="visibility: hidden; top: 129.5px; left: 106px; position: absolute;" class="zoomPreload">Loading zoom</div></div>     </a>       </div>   <div class="name"><s:property value="model.pname"/></div>   <div class="sn">    <div>编号:<s:property value="model.pid"/></div>   </div>   <div class="info">    <dl>     <dt>商城价:</dt>     <dd>      <strong>¥:<s:property value="model.shop_price"/></strong>       参 考 价:       <del><s:property value="model.market_price"/></del>     </dd>    </dl>     <dl>      <dt>促销:</dt>      <dd>        <a target="_blank" title="限时抢购 (2014-07-30 ~ 2015-01-01)">限时抢购</a>      </dd>     </dl>     <dl>      <dt>    </dt>      <dd>       <span>    </span>      </dd>     </dl>   </div>   <form id="cartForm" action="${ pageContext.request.contextPath }/cart_addCart.action" method="post" >    <input type="hidden" name="pid" value="<s:property value="model.pid"/>"/>    <div class="action">      <dl class="quantity">       <dt>购买数量:</dt>       <dd>        <input id="count" name="count" value="1" maxlength="4" onpaste="return false;" type="text"/>       </dd>       <dd>        件       </dd>      </dl>           <div class="buy">       <input id="addCart" class="addCart" value="加入购物车" type="button" onclick="saveCart()"/>     </div>    </div>   </form>   <div id="bar" class="bar">    <ul>      <li id="introductionTab">       <a href="#introduction">商品介绍</a>      </li>          </ul>   </div>        <div id="introduction" name="introduction" class="introduction">     <div class="title">      <strong><s:property value="model.pdesc"/></strong>     </div>     <div>      <img src="${pageContext.request.contextPath }/<s:property value="model.image"/>">     </div>    </div>              </div> </div><div class="container footer"> <div class="span24">  <div class="footerAd">     <img src="image\r___________renleipic_01/footer.jpg" alt="我们的优势" title="我们的优势" height="52" width="950"></div></div> <div class="span24">  <ul class="bottomNav">     <li>      <a href="#">关于我们</a>      |     </li>     <li>      <a href="#">联系我们</a>      |     </li>     <li>      <a href="#">诚聘英才</a>      |     </li>     <li>      <a href="#">法律声明</a>      |     </li>     <li>      <a>友情链接</a>      |     </li>     <li>      <a target="_blank">支付方式</a>      |     </li>     <li>      <a target="_blank">配送方式</a>      |     </li>     <li>      <a >SHOP++官网</a>      |     </li>     <li>      <a>SHOP++论坛</a>           </li>  </ul> </div> <div class="span24">  <div class="copyright">Copyright © 2005-2015 网上商城 版权所有</div> </div></div></body></html>
       来看一下我们的运行效果,首先运行我们的首页,运行效果如下图所示:

       【项目实战】---商品详情页的制作

      点击左边第一个商品,跳转到如下界面:

       【项目实战】---商品详情页的制作

       小编寄语:该博客小编主要简单的介绍了,点击商品如何跳转到该商品的详情页面,总的来说实现的思路分为四个方面,首先第一步,根据商品的id找到某个商品的详情链接,接着编写Action里面的内容,编写Action类,继承ActionSupport实现模型驱动接口,编写一个可以执行的方面,第三步配置Action,最后在Action中调用servcie完成根据ID进行查询的方法,小小的功能,大大的喜悦,还请小伙伴多多指教,网上商城,未完待续!!!!!


           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

【项目实战】---商品详情页的制作