zoukankan      html  css  js  c++  java
  • CShop Project 07: 开发新品推荐在首页的显示

    1.GoodsDao.java

    public List<Map<String, Object>> getGoodsList(int recommendType) throws SQLException {
            QueryRunner r = new QueryRunner(DBUtil.getDataSource());
            String sql = "select g.id,g.name,g.cover,g.price,t.name typename from recommend r,goods g,type t where type=? and r.goods_id=g.id and g.type_id=t.id";
            return r.query(sql,new MapListHandler(),recommendType);
        }

    2. GoodsService.java

        public List<Map<String, Object>> getNewGoodsList() {
            List<Map<String, Object>> list = null;
            try {
                list = gDao.getGoodsList(3);  // 新品的Type值为3  
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return list;
        }

    3. IndexServlet.java

    protected void doGet(){
            List<Map<String, Object>> newList = gService.getNewGoodsList();
            request.setAttribute("newList", newList);
    }    

    4. index.jsp

    <div class="clearfix"></div>
                <div class="alert alert-info">新品推荐</div>
                <div class="gallery-grids">    

    <c:forEach items="${newList }" var="g"> <div class="col-md-3 gallery-grid "> <a href="detail.action?goodid=14"> <img src="${pageContext.request.contextPath }${g.cover}" class="img-responsive" alt="${g.name }"/> </a> <div class="gallery-info"> <p> <span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> <a href="detail.action?goodid=14">查看详情</a> </p> <a class="shop" href="javascript:;" onclick="buy(14)">立刻购买</a> <div class="clearfix"> </div> </div> <div class="galy-info"> <p>${g.typeName } > ${g.name }</p> <div class="galry"> <div class="prices"> <h5 class="item_price">¥ ${g.price }</h5> </div> <div class="clearfix"></div> </div> </div> </div> </c:forEach> </div> </div> </div>
  • 相关阅读:
    难得之货,令人行妨
    Oracle死锁
    log4j杂记
    Oracle9或11使用了Oracle10的驱动引起的时间丢失
    程序员要重视过劳
    oracle提供的有用函数(待续)
    Mysql扩展之replication概述
    @autowired与@qualifer的使用区别备忘
    Oracle中的in参数的个数限制
    java版正则式提取替换示例
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13551658.html
Copyright © 2011-2022 走看看