电商网站模块设计 - 商品列表、导航、订单功能实现
该代码块是一个电商网站的模块设计,包含了以下几个功能模块:
-
findFloorsHotProducts(int start, int pagesize): 根据起始位置和每页数量,查询热门商品列表并按楼层分组返回。 -
navigationBar(): 查询导航栏分类列表并返回。 -
findProductListByCid(String cid, int currentPage, int pageSize): 根据分类ID和当前页码以及每页数量,查询该分类下的商品列表,并返回分页结果。 -
productInfo(String pid): 根据商品ID查询商品详细信息并返回。 -
submitOrders(Order order): 提交订单,包括保存订单信息和订单项信息。
整个代码块涵盖了电商网站的一些常见功能,包括查询商品列表、查询商品详细信息、生成订单等。每个功能模块都通过调用DAO层的方法实现具体的数据库操作,并将结果返回给调用者。
public List<FloorVo> findFloorsHotProducts(int start, int pagesize) {
List<FloorVo> floorVos =new ArrayList<FloorVo>();
try {
List<Pcode> pcodeList=pcodeDao.findPcodeListByCodeType('4');
for(Pcode pcode:pcodeList){
String param7 = pcode.getParam7();
FloorVo vo=new FloorVo();
vo.setFloorNo(param7);
String cid= pcode.getParam2();
List<Product> productList =dao.findHotProductListByPage(cid,start,pagesize);
vo.setProducts(productList);
floorVos.add(vo);
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return floorVos;
}
public List<Category> navigationBar() {
List<Category> categoryList =null;
try {
categoryList = dao.findAllCategorys();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
return categoryList;
}
public PageBean<Product> findProductListByCid(String cid, int currentPage, int pageSize) {
PageBean pageBean=null;
try {
int totalCount=dao.queryProductTotalCountByCid(cid);
pageBean=new PageBean(pageSize,totalCount);
pageBean.setCurrentPage(currentPage);
int start=(currentPage-1) * pageSize;
List<Product> productList=dao.findProductListByPage(cid,start,pageSize);
pageBean.setList(productList);
} catch (SQLException e) {
throw new RuntimeException(e);
}
return pageBean;
}
public Product productInfo(String pid){
Product product= null;
try {
product = dao.findProductByPid(pid);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return product;
}
//生成订单
public void submitOrders(Order order){
try {
dao.saveOrder(order);
dao.saveOrderItems(order);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
原文地址: https://www.cveoy.top/t/topic/p8Rd 著作权归作者所有。请勿转载和采集!