ssm-学子商城-项目第十天

3.商品展示

调整页面:index.jsp页面上给三级分类添加超级链接

  • ${computer.name}
  • 调整GoodsController控制器类

    给方法添加参数
    @RequestMapping("/showSearch.do")
    public String showSearch(Integer categoryId){
    
        return "search";
    }
    

    3.1 商品展示-持久层

    3.2 商品展示-业务层

    3.3 商品展示-控制器层

    public String showSearch(Integer categoryId,ModelMap map){
        //调用业务层的方法,返回集合
        List goodsList =
        goodsService.getGoodsByCategoryId(categoryId, 0, 12);
        //把集合设置到map
        map.addAttribute("goodsList",goodsList);        
    
        return "search";
    }
    

    3.4 商品展示-页面

    在search.jsp页面中显示商品信息

    ${goods.title}

    ${goods.price} 加入购物车

    调整页面:显示分页

    共28中商品,共4页|1 2 3 4

    显示共多少条记录 在GoodsMapper接口中定义方法

    Integer selectCount(Integer categoryId);
    

    在GoodsMapper.xml文件中,定义select节点,完成查询的功能

    
    

    在IGoodsService接口中定义方法

    Integer getCount(Integer categoryId);
    

    在GoodsService实现类中,调用持久层的方法,发回值

    在控制器方法中showSearch(),调用业务层方法,getCount(),得到记录数,把值设置map中

    //在map设置记录数
        map.addAttribute("count",goodsService.getCount(categoryId));
    

    在search.jsp页面上显示记录数

    共${count}种商品,共4页|1 2 3 4

    页面分页处理的完整代码

    共${count}种商品,共${pages}页| style="color:#ff0000" > ${i}

    4.商品详情

    4.1 商品详情页-持久层

    在GoodsMapper接口中定义方法

    Goods selectByGoodsId(Integer id);
    

    在GoodsMapper.xml编写select语句

    
    

    测试:

    4.2 商品详情页-业务层

    在IGoodsService 接口中定义方法

    Goods getGoodsById(Integer id);
    

    在GoodsService类中实现方法,返回持久层的对象

    测试:

    4.3 商品详情页-控制器层

    /goods/goodsInfo.do
    请求参数:goodsId,categoryId
    请求方式:GET
    响应方式:转发
    @
    public String goodsInfo(Integer goodsId,Integer categoryId,ModelMap map){
        //1.调用业务层方法 getGoodsById(goodsId),返回goods对象
        //2.把goods对象设置到map中
        //3.return "product_details";
    }
    

    把productdetails.html改写成productdetails.jsp

    4.4 商品详情页-页面

    在search.jsp页面上调整代码:在图片和titile的链接上调用toItemInfo函数: οnclick="toItemInfo(${goods.id},${goods.categoryId})"

        
    

    在index.jsp页面上调整代码,给热卖的商品添加链接,到商品详情

    
    查看详情
    
    

    在商品详情页product_details.jsp页面上显示动态数据

    图片
    

    ${goods.itemType}

    ${goods.title}

    学员售价:¥${goods.price}
    服务承诺: *退货补运费 *30天无忧退货 *48小时快速退款 *72小时发货

    4.5 商品详情-为您推荐

    在GoodsController类的goodsInfo方法中,调用业务层方法getGoodsByCategoryId(),得到装4个商品的List ,把list设置到map中;

    //查询该分类的热门商品4个
        List goodsList=
                goodsService.getGoodsByCategoryId(categoryId, 0, 4);
        //把goodsList设置到map中
        map.addAttribute("goodsList",goodsList);
    

    在product_details.jsp页面显示数据。

    
                 

    ${goods.title}

    购物车

    设计表 t_cart

    create table t_cart(
        id int auto_increment primary key,
        uid int not null,
        goods_id varchar(200),
        count int,
        created_user varchar(50),
        created_time date,
        modified_user varchar(50),
        modified_time date      
    )default charset=utf8;
    

    1.添加购物车

    1.1 添加购物车-持久层

    新建Cart实体类,然后新建CartMapper接口,在接口中定义方法

    void insertCart(Cart cart)
    

    新建CartMapper.xml(拷贝,改名),定义insert节点,完成插入数据功能

    
        
            insert into t_cart(
                uid,goods_id,count,
                created_user,created_time,
                modified_user,modified_time
            )values(
               #{uid},#{goodsId},#{count},
               #{createdUser},#{createdTime},
               #{modifiedUser},#{modifiedTime}
            )
        
    
    

    测试:

    你可能感兴趣的:(ssm-学子商城)