按照页面原型设计
- 点击全部商店后加载一级商铺列表,加载对应的数据
- 点击特定的一级商铺列表,加载对应商铺列表下的数据
- 区域显示全部区域
- 店铺列表页面需要支持分页功能,使用无极滚动的样式
- 店铺列表页面需要支持多条件排列组合查询店铺信息
<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