在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
节点
测试:
新建IGoodsCategoryService接口,在接口中定义方法
List getCategoryByParentId(Integer parentId,Integer offset,Integer count);
新建GoodsCategoryService实现类,在接口中实现方法,方法功能:调用持久层的方法,并返回集合
测试:
使用MainController类中的showIndex方法中定义集合, 调用业务层方法的的集合
public String showIndex(ModelMap map){
定义集合computerList,
1.调用getCategoryByParentId(161,0,3),返回二级分类,赋值给computerList;
2.定义集合category161List;遍历二级分类集合,得到二级分类的对象,从对象中得到id,调用getCategoryByParentId(id,null,null),返回三级分类集合,把三级分类的集合添加到category161List。
3.把两个集合分别设置到map
}
${computerList[0].name}
${computerList[1].name}
${computerList[2].name}
新建Goods实体类;然后新建GoodsMapper接口,在接口中定义方法
List select(
@Param("categoryId") Integer categoryId,
@Param("offset") Integer offset,
@Param("count") Integer count)
新建GoodsMapper.xml(拷贝,改名);注意: ,定义select
节点,完成select语句
测试:
新建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 调用持久层方法,返回集合
}
}
测试:
在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";
}
显示商品的页面,search.html,该为search.jsp; 新建GoodsControler类,定义showSearch方法,完成显示页面
@RequestMapping("/goods")
@Controller
public class GoodsController extends BaseController{
@RequestMapping("/showSearch.do")
public String showSearch(){
return "search";
}
}