1.实现选择某个品牌,加载这个品牌的数据;在已选条件中显示选择的品牌;品牌列表消失
2.选择品牌后,再选择类型,加载品牌类型对应的数据,已选条件显示对应的品牌和类型;品牌类型列表消失,如下所示.

这里写图片描述

这里写图片描述

流程图:
这里写图片描述

jsp

<c:if test="${!empty brandList }">
                    <li><b>品牌:</b>
                    <p><a href="javascript:void(0);" title="不限" class="here">不限</a>
                            <c:forEach items="${brandList }" var="brand">
                                <a href="javascript:void(0);" title="${brand.name }"
                                    onclick="window.location.href='/product/display/list.shtml?brandId=${brand.id}&brandName=${brand.name }&typeId=${typeId}&typeName=${typeName }'">${brand.name }</a>
                            </c:forEach>
                        </p></li>
                </c:if>
                <li><b>价格:</b>
                <p><a href="javascript:void(0);" title="不限" class="here">不限</a> <a
                            href="javascript:void(0);" title="1-99">0-79</a> <a
                            href="javascript:void(0);" title="100-199">80-199</a> <a
                            href="javascript:void(0);" title="200-499">600以上</a>
                    </p></li>
                <c:if test="${!empty typeList}">
                    <li><b>类型:</b>
                    <p>
                            <a href="javascript:void(0);" title="不限" class="here">不限</a>
                            <c:forEach items="${typeList }" var="type">
                                <a href="javascript:void(0);" title="${type.name }"
                                    onclick="window.location.href='/product/display/list.shtml?typeId=${type.id}&typeName=${type.name }&brandId=${brandId}&brandName=${brandName }'">${type.name }</a>
                            </c:forEach>
                        </p></li>
                </c:if>

controller

    public String list(String typeName, Integer typeId, String brandName, Integer brandId, Integer pageNo,
            ModelMap modelMap) {
        StringBuilder sb = new StringBuilder();

        // 获取属性数据集
        FeatureQuery featureQuery = new FeatureQuery();
        List<Feature> featureList = featureService.getFeatureList(featureQuery);
        modelMap.addAttribute("featureList", featureList);

        // 获取商品数据集
        ProductQuery productQuery = new ProductQuery();
        // 设置页号
        productQuery.setPageNo(Pagination.cpn(pageNo));
        // 设置每页数
        productQuery.setPageSize(Product.FRONT_PAGE_SIZE);
        // 设置排序,商品Id降序
        productQuery.orderbyId(false);

        // 条件TODO
        // 隐藏已选条件的条件行
        boolean flag = false;
        //query 显示已选的品牌 类型
        Map<String, String> query = new LinkedHashMap<String, String>();
        // 品牌id
        if (brandId != null) {
            productQuery.setBrandId(brandId);
            flag = true;
            query.put("品牌", brandName);
            modelMap.addAttribute("brandId", brandId);
            modelMap.addAttribute("brandName", brandName);
            sb.append("&brandId=").append(brandId).append("&brandName=").append(brandName);
        } else {
            // 获取品牌的数据集,product。jsp页面第一次加载,brandid为null,加载品牌数据,后期选择品牌后,不加载品牌数据
            BrandQuery brandQuery = new BrandQuery();
            brandQuery.setFields("id,name");
            brandQuery.setIsDisplay(1);
            List<Brand> brandList = brandService.getBrandList(brandQuery);
            modelMap.addAttribute("brandList", brandList);
        }
        // 类型id
        if (typeId != null) {
            productQuery.setTypeId(typeId);
            flag = true;
            query.put("类型", typeName);
            modelMap.addAttribute("typeName", typeName);
            modelMap.addAttribute("typeId", typeId);
            sb.append("&typeId=").append(typeId).append("&typeName=").append(typeName);
        } else {
            // 加载商品类型
            TypeQuery typeQuery = new TypeQuery();
            // 设置指定字段
            typeQuery.setFields("id,name");
            // 设置可见
            typeQuery.setIsDisplay(1);
            // 除了父ID以外的
            typeQuery.setParentId(0);
            // 获取数据集
            List<Type> typeList = typeService.getTypeList(typeQuery);
            // 加载到页面
            modelMap.addAttribute("typeList", typeList);
        }
        modelMap.addAttribute("flag", flag);
        modelMap.addAttribute("query", query);

        // 获取商品分页数据
        Pagination pagination = productService.getProductListWithPage(productQuery);
        // 分页选项,拼接地址
        String url = "/product/display/list.shtml";
        pagination.pageView(url, sb.toString());
        modelMap.addAttribute("pagination", pagination);

        return "product/product";
    }
posted on 2017-04-18 16:25  2637282556  阅读(127)  评论(0编辑  收藏  举报