zoukankan      html  css  js  c++  java
  • 校园商铺-9前端展示系统-8店铺详情页的开发

    1.controller层

    package com.csj2018.o2o.web.frontend;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import com.csj2018.o2o.dto.ProductExecution;
    import com.csj2018.o2o.entity.Product;
    import com.csj2018.o2o.entity.ProductCategory;
    import com.csj2018.o2o.entity.Shop;
    import com.csj2018.o2o.service.ProductCategoryService;
    import com.csj2018.o2o.service.ProductService;
    import com.csj2018.o2o.service.ShopService;
    import com.csj2018.o2o.util.HttpServletRequestUtil;
    
    @Controller
    @RequestMapping(value="/frontend")
    public class ShopDetailController {
    	@Autowired
    	private ShopService shopService;
    	@Autowired
    	private ProductService productService;
    	@Autowired
    	private ProductCategoryService productCategoryService;
    	/**
    	 * 查询店铺信息和店铺下的商品分类
    	 * @param request
    	 * @return
    	 */
    	@RequestMapping(value="/listshopdetailpageinfo",method=RequestMethod.GET)
    	@ResponseBody
    	private Map<String,Object> listShopDetailInfo(HttpServletRequest request){
    		Map<String,Object> modelMap = new HashMap<String,Object>();
    		//获取前台传过来的shopId
    		long shopId = HttpServletRequestUtil.getLong(request, "shopId");
    		Shop shop = null;
    		List<ProductCategory> productCategoryList = null;
    		if(shopId != -1) {
    			//获取店铺信息
    			shop = shopService.getByShopId(shopId);
    			//获取店铺的商品分类
    			productCategoryList = productCategoryService.getProductCategoryList(shopId);
    			modelMap.put("shop", shop);
    			modelMap.put("productCategoryList", productCategoryList);
    			modelMap.put("success", true);
    		}else {
    			modelMap.put("success","false");
    			modelMap.put("errMsg", "empty shopId");
    		}
    		return modelMap;
    	}
    	
    	@RequestMapping(value="listproductsbyshop",method=RequestMethod.GET)
    	@ResponseBody
    	private Map<String,Object> listProductsByShop(HttpServletRequest request){
    		Map<String,Object> modelMap = new HashMap<String,Object>();
    		//获取页码
    		int pageIndex = HttpServletRequestUtil.getInt(request, "pageIndex");
    		int pageSize = HttpServletRequestUtil.getInt(request, "pageSize");
    		long shopId = HttpServletRequestUtil.getLong(request, "shopId");
    		//空值判断
    		if((pageIndex > -1)&&(pageSize > -1)&&(shopId > -1)) {
    			//获取筛选条件
    			long productCategoryId = HttpServletRequestUtil.getLong(request, "productCategoryId");
    			String productName = HttpServletRequestUtil.getString(request, "productName");
    			//组合查询
    			Product productCondition = compactProductCondition4Search(shopId,productCategoryId,productName);
    			//
    			ProductExecution pe = productService.getProductList(productCondition, pageIndex, pageSize);
    			modelMap.put("productList", pe.getProductList());
    			modelMap.put("count", pe.getCount());
    			modelMap.put("success", true);
    		}else {
    			modelMap.put("success", "false");
    			modelMap.put("errMsg", "empty pageSize or pageIndex or shopId");
    		}
    		return modelMap;
    	}
    	
    	private Product compactProductCondition4Search(long shopId,long productCategoryId,String productName) {
    		Product productCondition = new Product();
    		Shop shop = new Shop();
    		shop.setShopId(shopId);
    		productCondition.setShop(shop);
    		if(productCategoryId != -1) {
    			//查询某个商品类别下面的商品列表
    			ProductCategory productCategory = new ProductCategory();
    			productCategory.setProductCategoryId(productCategoryId);
    			productCondition.setProductCategory(productCategory);
    		}
    		if(productName != null) {
    			productCondition.setProductName(productName);
    		}
    		//只允许选出状态为上架的商品
    		productCondition.setEnableStatus(1);
    		return productCondition;
    	}
    }
    

    2.验证

    http://127.0.0.1:18080/o2o/frontend/listshopdetailpageinfo?shopId=1
    http://127.0.0.1:18080/o2o/frontend/listproductsbyshop?shopId=1&pageIndex=0&pageSize=3&productName=前端

  • 相关阅读:
    lr 增强窗格中,如何生成调试信息?
    lr 自带的例子,如何进行关联,通过代码的函数进行实现
    lr11 录制脚本时候,无法自动启动ie,查了网上很多方法都未解决?
    loadrunner11 录制脚步不成功,在录制概要出现“No Events were detected”,浮动窗口总是显示“0 Events”,解决办法
    loadrunner11 安装及破解教程来自百度文库
    安装loadrunner11 ,出现如下错误如何解决?
    回收站数据删除了,如何进行恢复?
    网管工作方面——————打印机删除了然后开机重启他依然存在,如何解决
    Windows 不能在 本地计算机 启动 SQL Server 服务 错误代码126
    Sorry, the page you are looking for is currently unavailable. Please try again later. Nginx
  • 原文地址:https://www.cnblogs.com/csj2018/p/12601088.html
Copyright © 2011-2022 走看看