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=前端

  • 相关阅读:
    AngularJS 国际化——Angular-translate
    Elasticsearch Span Query跨度查询
    Elasticsearch 连接查询
    Elasticsearch DSL中Query与Filter的不同
    Lucene查询语法详解
    Elasticsearch 文件目录解释
    Elasticsearch 安装与启动
    《大屏可视化数据》该怎么设计?
    两个大屏可视化案例的布局与实现
    maven 安装后变成 mvn 不是内部命令解决方法
  • 原文地址:https://www.cnblogs.com/csj2018/p/12601088.html
Copyright © 2011-2022 走看看