shop--11.前端展示系统--店铺列表(后端)

按照页面原型设计

  • 点击全部商店后加载一级商铺列表,加载对应的数据
  • 点击特定的一级商铺列表,加载对应商铺列表下的数据
  • 区域显示全部区域
  • 店铺列表页面需要支持分页功能,使用无极滚动的样式
  • 店铺列表页面需要支持多条件排列组合查询店铺信息

    <select id="queryShopList" resultMap="shopMap">
        SELECT
        s.shop_id,
        s.shop_name,
        s.shop_desc,
        s.shop_addr,
        s.phone,
        s.shop_img,
        s.priority,
        s.create_time,
        s.last_edit_time,
        s.enable_status,
        s.advice,
        a.area_id,
        a.area_name,
        sc.shop_category_id,
        sc.shop_category_name
        FROM
        tb_shop s,
        tb_area a,
        tb_shop_category sc
        <where>
            <if
                test="shopCondition.shopCategory!=null
                and shopCondition.shopCategory.shopCategoryId!=null">
                and s.shop_category_id =
                #{shopCondition.shopCategory.shopCategoryId}
            </if>
            <if
                test="shopCondition.shopCategory != null
                and shopCondition.shopCategory.parent!=null
                and shopCondition.shopCategory.parent.shopCategoryId!=null">
                and s.shop_category_id in (select shop_category_id from
                tb_shop_category
                WHERE parent_id =
                #{shopCondition.shopCategory.parent.shopCategoryId})
            </if>
            <if
                test="shopCondition.area!=null and shopCondition.shopCategory.areaId!=null">
                and shop_area_id = #{shopCondition.area.areaId}
            </if>
            <if test="shopCondition.shopName!=null">
                and s.shop_name like ‘%${shopCondition.shopName}%‘
            </if>
            <if test="shopCondition.enableStatus!=null">
                and s.enable_status = #{shopCondition.enableStatus}
            </if>
            <if
                test="shopCondition.owner!=null and shopCondition.owner.userId!=null">
                and s.owner_id = #{shopCondition.owner.userId}
            </if>
            AND
            s.area_id = a.area_id
            AND
            s.shop_category_id = sc.shop_category_id
        </where>
        ORDER BY
        s.priority DESC
        LIMIT #{rowIndex},#{pageSize};
    </select>
    <select id="queryShopCount" resultType="int">
        SELECT
        count(1)
        FROM
        tb_shop s,
        tb_area a,
        tb_shop_category sc
        <where>
            <if
                test="shopCondition.shopCategory!=null and shopCondition.shopCategory.shopCategoryId!=null">
                and s.shop_category_id =
                #{shopCondition.shopCategory.shopCategoryId}
            </if>
            <if
                test="shopCondition.shopCategory != null
                and shopCondition.shopCategory.parent!=null
                and shopCondition.shopCategory.parent.shopCategoryId!=null">
                and s.shop_category_id in (select shop_category_id from
                tb_shop_category
                WHERE parent_id =
                #{shopCondition.shopCategory.parent.shopCategoryId})
            </if>
            <if
                test="shopCondition.area!=null and shopCondition.shopCategory.areaId!=null">
                and shop_area_id = #{shopCondition.area.areaId}
            </if>
            <if test="shopCondition.shopName!=null">
                and s.shop_name like ‘%${shopCondition.shopName}%‘
            </if>
            <if test="shopCondition.enableStatus!=null">
                and s.enable_status = #{shopCondition.enableStatus}
            </if>
            <if
                test="shopCondition.owner!=null and shopCondition.owner.userId!=null">
                and s.owner_id = #{shopCondition.owner.userId}
            </if>
            AND
            s.area_id = a.area_id
            AND
            s.shop_category_id = sc.shop_category_id
        </where>
    </select>

为了找出二级目录

            <if
                test="shopCondition.shopCategory != null
                and shopCondition.shopCategory.parent!=null
                and shopCondition.shopCategory.parent.shopCategoryId!=null">
                and s.shop_category_id in (select shop_category_id from
                tb_shop_category
                WHERE parent_id =
                #{shopCondition.shopCategory.parent.shopCategotyId})
            </if>

shopListController.java

  1 package com.ryanxu.o2o.web.frontend;
  2
  3 import java.util.ArrayList;
  4 import java.util.HashMap;
  5 import java.util.List;
  6 import java.util.Map;
  7
  8 import javax.servlet.http.HttpServletRequest;
  9
 10 import org.springframework.beans.factory.annotation.Autowired;
 11 import org.springframework.stereotype.Controller;
 12 import org.springframework.web.bind.annotation.RequestMapping;
 13 import org.springframework.web.bind.annotation.RequestMethod;
 14 import org.springframework.web.bind.annotation.ResponseBody;
 15
 16 import com.ryanxu.o2o.dto.ShopExecution;
 17 import com.ryanxu.o2o.entity.Area;
 18 import com.ryanxu.o2o.entity.Shop;
 19 import com.ryanxu.o2o.entity.ShopCategory;
 20 import com.ryanxu.o2o.service.AreaService;
 21 import com.ryanxu.o2o.service.ShopCategoryService;
 22 import com.ryanxu.o2o.service.ShopService;
 23 import com.ryanxu.o2o.util.HttpServletRequestUtil;
 24
 25 @Controller
 26 @RequestMapping(value="/frontend")
 27 public class ShopListController {
 28     @Autowired
 29     private AreaService areaService;
 30     @Autowired
 31     private ShopCategoryService shopCategoryService;
 32     @Autowired
 33     private ShopService shopService;
 34
 35     /**
 36      * 返回商品列表页里的ShopCategory列表(二级或一级),以及区域信息列表
 37      *
 38      * @param request
 39      * @return
 40      */
 41     @RequestMapping(value = "/listshopspageinfo",method=RequestMethod.GET)
 42     @ResponseBody
 43     private Map<String, Object> listShopsPageInfo(HttpServletRequest request){
 44         Map<String, Object> modelMap = new HashMap<String,Object>();
 45         //试着从前端请求中获取parentId
 46         long parentId = HttpServletRequestUtil.getLong(request, "parentId");
 47         List<ShopCategory> shopCategoryList = new ArrayList<ShopCategory>();
 48
 49         if(parentId != -1) {
 50             //如果存在parentId,则取出该一级ShopCategory下的二级ShopCategory列表
 51             try {
 52                 ShopCategory shopCategoryCondition = new ShopCategory();
 53                 ShopCategory parent = new ShopCategory();
 54                 parent.setShopCategoryId(parentId);
 55                 shopCategoryCondition.setParent(parent);
 56                 shopCategoryList = shopCategoryService.getShopCategoryList(shopCategoryCondition);
 57             }catch (Exception e) {
 58                 modelMap.put("success", false);
 59                 modelMap.put("errMsg", e.getMessage());
 60             }
 61         }else {
 62             try {
 63                 //如果parentId不存在,则取出所有一级ShopCategory(用户在首页选择的是全部商品列表)
 64                 shopCategoryList = shopCategoryService.getShopCategoryList(null);
 65             }catch (Exception e) {
 66                 modelMap.put("success", false);
 67                 modelMap.put("errMsg", e.getMessage());
 68             }
 69         }
 70         modelMap.put("shopCategoryList", shopCategoryList);
 71         List<Area> areaList = null;
 72         try {
 73             //获取区域列表信息
 74             areaList = areaService.getAreaList();
 75             modelMap.put("areaList", areaList);
 76             modelMap.put("success", true);
 77             return modelMap;
 78         }catch (Exception e) {
 79             modelMap.put("success", false);
 80             modelMap.put("errMsg", e.getMessage());
 81         }
 82         return modelMap;
 83     }
 84
 85     /**
 86      * 获取指定查询条件下的店铺列表
 87      *
 88      * @param request
 89      * @return
 90      */
 91     @RequestMapping(value="/listshops",method = RequestMethod.GET)
 92     @ResponseBody
 93     private Map<String, Object> listShops(HttpServletRequest request){
 94         Map<String, Object> modelMap = new HashMap<String,Object>();
 95         //获取页码
 96         int pageIndex = HttpServletRequestUtil.getInt(request, "pageIndex");
 97         //获取一页所需显示的数据条数
 98         int pageSize = HttpServletRequestUtil.getInt(request, "pageSize");
 99         //非空判断
100         if((pageIndex > -1)&&(pageSize > -1)) {
101             //试着获取一级类别Id
102             long parentId = HttpServletRequestUtil.getLong(request, "parentId");
103             //试着获取特定二级类别Id
104             long shopCategoryId = HttpServletRequestUtil.getLong(request, "shopCategoryId");
105             //试着获取区域Id
106             int areaId = HttpServletRequestUtil.getInt(request, "areaId");
107             //试着获取模糊查询的名字
108             String shopName = HttpServletRequestUtil.getString(request, "shopName");
109             //获取组合之后的查询条件
110             Shop shopCondition = compactShopCondition4Search(parentId,shopCategoryId,areaId,shopName);
111             //根据查询条件和分页信息获取店铺列表,并返回总数
112             ShopExecution se = shopService.getShopList(shopCondition, pageIndex, pageSize);
113             modelMap.put("shopList", se.getShopList());
114             modelMap.put("count", se.getCount());
115             modelMap.put("success", true);
116         }else {
117             modelMap.put("success", false);
118             modelMap.put("errMsg", "empty pageSize or pageIndex");
119         }
120         return modelMap;
121     }
122
123     /**
124      * 组合查询条件,并将条件封装到ShopCondition对象里返回
125      *
126      * @param parentId
127      * @param shopCategoryId
128      * @param areaId
129      * @param shopName
130      * @return
131      */
132     private Shop compactShopCondition4Search(long parentId, long shopCategoryId, int areaId, String shopName) {
133         Shop shopCondition = new Shop();
134         if(parentId != -1L) {
135             //查询某一个一级ShopCategory下面的所有二级ShopCategory里面的店铺列表
136             ShopCategory childCategory = new ShopCategory();
137             ShopCategory parentCategory = new ShopCategory();
138             parentCategory.setShopCategoryId(parentId);
139             childCategory.setParent(parentCategory);
140             shopCondition.setShopCategory(childCategory);
141         }
142         if(shopCategoryId != -1L) {
143             //查询某个二级ShopCategory下面的店铺列表
144             ShopCategory shopCategory = new ShopCategory();
145             shopCategory.setShopCategoryId(shopCategoryId);
146             shopCondition.setShopCategory(shopCategory);
147         }
148         if(areaId != -1L) {
149             //查询位于某个区域Id下的店铺列表
150             Area area = new Area();
151             area.setAreaId(areaId);
152             shopCondition.setArea(area);
153         }
154         if(shopName != null ) {
155             //查询名字里包含shopName的店铺列表
156             shopCondition.setShopName(shopName);
157         }
158         //前端展示的店铺都是审核通过的店铺
159         shopCondition.setEnableStatus(1);
160         return shopCondition;
161     }
162 }

第二个if相当于这样 shop表里的

原文地址:https://www.cnblogs.com/windbag7/p/9425997.html

时间: 2024-11-09 15:27:02

shop--11.前端展示系统--店铺列表(后端)的相关文章

shop--11.前端展示系统--店铺详情(后端)

大多与店铺列表展示页面相同 shopdetail.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>商店详情</title> <meta name="viewpo

校园商铺-9前端展示系统-9店铺详情页的前端开发

1.前端 1.1 html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>商店详情</title> <meta name="viewport" content

校园商铺-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.springf

shop--11.前端展示系统--首页展示(前端)

index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>我的生活</title> <meta name="viewport" content=&q

shop--10.店铺列表(前端)

利用SUI Mobile的模板来进行拼装 http://m.sui.taobao.org/components/#searchbar 搜索栏.栅栏和按钮组合 卡片 无限滚动 shoplist.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=ed

shop--8.店铺列表展示--Dao层

实现商铺管理 实现商店列表 实现分页查询店铺,通过条件组合,来筛选出条件范围内的店铺列表 分页查询中使用LIMIT 第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目 1 /** 2 * 分页查询店铺,可输入的条件有:店铺名(模糊),店铺状态,店铺类别,区域id,owner 3 * @param shopCondition 4 * @param rowIndex 从第几行开始取数据 5 * @param pageSize 表示返回多少行数据 6 * @param 标签的作

shop--8.店铺列表展示--Service层

在service层中, 有一个问题,就是: dao层中的分页查询传参,传入的是rowIndex(从第几行开始查询), pageSize(查询多少条记录) 而在service层中分页查询传的是pageIndex(第几页),pageSize 所以在第一个参数要有一个转换才可以 所以编写一个工具类,将pageIndex转为rowIndex PageCalculator 1 /** 2 * 将pageIndex(第几页)转换为查询结果中的第几行rowIndex 3 * 如果pageIndex是1 pag

校园商铺-6店铺编辑列表和列表功能-6店铺列表展示之Service层的实现

1. Service层 为什么返回shopExecution? 原因:需要将这个shopList还有它的count整合在一起返回.而shopExecution正好满足了我们的条件. package com.csj2018.o2o.service; import java.io.InputStream; import com.csj2018.o2o.entity.Shop; import com.csj2018.o2o.exceptions.ShopOperationException; impo

第八章 交互技术,8.3 2016双11前端突破(作者:天猫前端团队)

8.3 2016双11前端突破 前言 2016 年天猫前端相比去年有了非常多不同维度的突破,主要可以分为四大类大类: 稳定性.监控 极致的性能优化 业务创新 / 平台建设 技术创新 / 互动 1. 稳定性.监控 商品到每个用户浏览的每个环节都有监控,尤其在针对消费者体验上的 TES,让前端在消费者真实浏览的过程当中也能够有更进一步的分析在不同环境下消费者实际的体验.以及从服务器 Wormhole 渲染层进行了一系列的稳定性.监控. 1.1 Wormhole双11会场稳定性保障 Wormhole承