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

商品分类及商品展示

1.商品分类

1.1 商品分类-持久层

在ftp下载商品基本数据,解压后,一个portal压缩文件,解压到portal文件夹,把portal拷贝到TeduStore工程webapp的image是问价夹中;然后在mysql的客户端执行source 盘符:goods.sql;导入表是数据

首先新建GoodsCategory实体类;定义接口GoodsCategoryMapper,在接口中定义方法

List selectCategoryByParentId(
@Param("parentid") Integer parentId,
@Param("offset") Integter offset,
@Param("count") Integer count);

新建GoodsCategoryMapper.xml(拷贝,改名);需要注意的地方:;然后定义select节点


测试:

1.2 商品分类-业务层

新建IGoodsCategoryService接口,在接口中定义方法

List getCategoryByParentId(Integer parentId,Integer offset,Integer count);

新建GoodsCategoryService实现类,在接口中实现方法,方法功能:调用持久层的方法,并返回集合

测试:

1.3 商品分类-控制器层

使用MainController类中的showIndex方法中定义集合, 调用业务层方法的的集合

public String showIndex(ModelMap map){
    定义集合computerList,
    1.调用getCategoryByParentId(161,0,3),返回二级分类,赋值给computerList;
    2.定义集合category161List;遍历二级分类集合,得到二级分类的对象,从对象中得到id,调用getCategoryByParentId(id,null,null),返回三级分类集合,把三级分类的集合添加到category161List。

    3.把两个集合分别设置到map


}

1.4 商品分类-页面

${computerList[0].name}

${computerList[1].name}

${computerList[2].name}

2 热门商品的显示

2.1 热门商品显示-持久层

新建Goods实体类;然后新建GoodsMapper接口,在接口中定义方法

List select(
@Param("categoryId") Integer categoryId,
@Param("offset") Integer offset,
@Param("count") Integer count)

新建GoodsMapper.xml(拷贝,改名);注意: ,定义select节点,完成select语句


测试:

2.2 热门商品显示-业务层

新建IGoodsService接口,在接口中定义方法

List getGoodsByCategoryId(
        Integer cartegoryId,Integer offset,Integer count);

新建GoodsService实现类,实现接口中的方法

@Service
public class GoodsService implements IGoodsService{
    @Resource
    private GoodsMapper goodsMapper;
    public List getGoodsByCategoryId(
        Integer categoryId,Integer offset,Integer count){
        return 调用持久层方法,返回集合
    }
}

测试:

2.3 热门商品显示-控制器层

在MainController类的showIndex方法中,调用业务 层方法,把返回的集合设置到map中。

@Resource
private IGoodsService goodsService;
public String showIndex(ModelMap map){
.....
    //热门商品的集合
    List goodsList = goodsService.getGoodsByCategoryId(163,0,3);

map.addAttribute("goodsList",goodsList);
return "index";
}

2.4 热门商品-页面

 
    

${goods.title}

¥${goods.price}

查看详情

3.商品展示页

显示商品的页面,search.html,该为search.jsp; 新建GoodsControler类,定义showSearch方法,完成显示页面

@RequestMapping("/goods")
@Controller
public class GoodsController extends BaseController{

    @RequestMapping("/showSearch.do")
    public String showSearch(){
        return "search";
    }
}

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