日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

实战SSM_O2O商铺_41【前端展示】店铺列表页面Dao+Service+Controller层的实现

發布時間:2025/3/21 HTML 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实战SSM_O2O商铺_41【前端展示】店铺列表页面Dao+Service+Controller层的实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 概述
  • Dao層
    • 接口
    • 映射文件
    • 單元測試
  • Service層
    • 接口方法
    • 單元測試
  • Controller層
    • 增加 ShopListController
    • 單元測試
  • Github地址

概述

在完成了首頁輪播圖和首頁商品分類的展示之后,

按照頁面原型設計

  • 點擊全部商店后加載一級商鋪列表,加載對應的數據

  • 點擊特定的一級商鋪列表,加載對應商鋪列表下的數據

  • 區域顯示全部區域

  • 店鋪列表頁面需要支持分頁功能,使用無極滾動的樣式

  • 店鋪列表頁面需要支持多條件排列組合查詢店鋪信息

如下


Dao層

接口

復用ShopDao#selectShopList方法

List<Shop> selectShopList(@Param("shopCondition") Shop shopCondition, @Param("rowIndex") int rowIndex, @Param("pageSize") int pageSize);

映射文件

增加如下查詢條件,滿足當用戶點擊某個一級商鋪類別的時候,加載改商鋪類別下全部的商鋪。

<!-- 選擇了某個大類,列舉出該大類下面的全部商店 以parent_id來篩選 --><if test="shopCondition.shopCategory != null and shopCondition.shopCategory.parent != nulland 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>

單元測試

表中的數據

@Testpublic void testSelectShopListAndCount2() {// 根據表中的數據 共計6條數據// 其中 2條 屬于 【咖啡】二級商鋪類別// 其中 2條 屬于 【奶茶】二級商鋪類別// 其中 2條 屬于 【考研輔導】二級商鋪類別// 而 【咖啡】和【奶茶】二級商鋪類別 屬于 【美食飲品】一級商鋪類別// 模擬用戶點擊【美食飲品】,查詢出來屬于 【美食飲品】下面的商鋪 ,// 期望符合條件的數據為 2條 屬于 【咖啡】二級商鋪類別的店鋪 + 2條 屬于 【奶茶】二級商鋪類別 的店鋪/*** * <!-- 選擇了某個大類,列舉出該大類下面的全部商店 以parent_id來篩選 --> <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>* * * */Shop shopCondition = new Shop();// 模擬ShopCategory childShopCategory = new ShopCategory();ShopCategory parentShopCategory = new ShopCategory();// 設置父類的shopCategoryIdparentShopCategory.setShopCategoryId(3L);// 設置父子關系childShopCategory.setParent(parentShopCategory);// 設置目錄shopCondition.setShopCategory(childShopCategory);List<Shop> shoplist = shopDao.selectShopList(shopCondition, 0, 5);int count = shopDao.selectShopCount(shopCondition);Assert.assertEquals(4, shoplist.size());Assert.assertEquals(4, count);for (Shop shop : shoplist) {System.out.println(shop.toString());}}

日志

==> Preparing: 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 s.shop_category_id in ( select shop_category_id from tb_shop_category where parent_id = ? ) AND s.area_id = a.area_id AND s.shop_category_id = sc.shop_category_id ORDER BY s.priority DESC LIMIT ? , ? Sat Aug 04 11:44:36 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Sat Aug 04 11:44:36 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. ==> Parameters: 3(Long), 0(Integer), 5(Integer) <== Columns: shop_id, shop_name, shop_desc, shop_addr, phone, shop_img, priority, create_time, last_edit_time, enable_status, advice, area_id, area_name, shop_category_id, shop_category_name <== Row: 4, 咖啡店1, 咖啡店1簡介, 東方明珠, 1234, \upload\item\shopImage\4\2018072718443825588.jpg, 99, 2018-07-27 10:44:39, 2018-07-27 10:44:39, 1, null, 2, 上海, 7, 咖啡 <== Row: 5, 咖啡店2, 咖啡店2簡介, 上海某地, 123456, \upload\item\shopImage\5\2018080410065694536.jpg, 98, 2018-08-04 02:06:56, 2018-08-04 02:35:51, 1, Waring UP, 2, 上海, 7, 咖啡 <== Row: 6, 奶茶店1, 奶茶店1簡介, 東直門, 654321, \upload\item\shopImage\6\2018080410074110364.jpg, 97, 2018-08-04 02:07:42, 2018-08-04 02:07:42, 1, null, 1, 北京, 9, 奶茶 <== Row: 7, 奶茶店2, 奶茶店2簡介, 798藝術區, 56789, \upload\item\shopImage\7\2018080410094723088.jpg, 96, 2018-08-04 02:09:48, 2018-08-04 02:09:48, 1, null, 1, 北京, 9, 奶茶 <== Total: 4 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@78641d23] Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2c1156a7] was not registered for synchronization because synchronization is not active JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@691939c9] will not be managed by Spring ==> Preparing: SELECT count(1) FROM tb_shop s, tb_area a, tb_shop_category sc WHERE s.shop_category_id in ( select shop_category_id from tb_shop_category where parent_id = ? ) AND s.area_id = a.area_id AND s.shop_category_id = sc.shop_category_id ==> Parameters: 3(Long) <== Columns: count(1) <== Row: 4 <== Total: 1 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2c1156a7] Shop [shopId=4, shopName=咖啡店1, shopDesc=咖啡店1簡介, shopAddr=東方明珠, phone=1234, shopImg=\upload\item\shopImage\4\2018072718443825588.jpg, priority=99, createTime=Fri Jul 27 18:44:39 CST 2018, lastEditTime=Fri Jul 27 18:44:39 CST 2018, enableStatus=1, advice=null, owner=null, area=Area [areaId=2, areaName=上海, areaDesc=null, priority=null, createTime=null, lastEditTime=null], shopCategory=ShopCategory [shopCategoryId=7, shopCategoryName=咖啡, shopCategoryDesc=null, shopCategoryImg=null, priority=null, createTime=null, lastEditTime=null, parent=null]] Shop [shopId=5, shopName=咖啡店2, shopDesc=咖啡店2簡介, shopAddr=上海某地, phone=123456, shopImg=\upload\item\shopImage\5\2018080410065694536.jpg, priority=98, createTime=Sat Aug 04 10:06:56 CST 2018, lastEditTime=Sat Aug 04 10:35:51 CST 2018, enableStatus=1, advice=Waring UP, owner=null, area=Area [areaId=2, areaName=上海, areaDesc=null, priority=null, createTime=null, lastEditTime=null], shopCategory=ShopCategory [shopCategoryId=7, shopCategoryName=咖啡, shopCategoryDesc=null, shopCategoryImg=null, priority=null, createTime=null, lastEditTime=null, parent=null]] Shop [shopId=6, shopName=奶茶店1, shopDesc=奶茶店1簡介, shopAddr=東直門, phone=654321, shopImg=\upload\item\shopImage\6\2018080410074110364.jpg, priority=97, createTime=Sat Aug 04 10:07:42 CST 2018, lastEditTime=Sat Aug 04 10:07:42 CST 2018, enableStatus=1, advice=null, owner=null, area=Area [areaId=1, areaName=北京, areaDesc=null, priority=null, createTime=null, lastEditTime=null], shopCategory=ShopCategory [shopCategoryId=9, shopCategoryName=奶茶, shopCategoryDesc=null, shopCategoryImg=null, priority=null, createTime=null, lastEditTime=null, parent=null]] Shop [shopId=7, shopName=奶茶店2, shopDesc=奶茶店2簡介, shopAddr=798藝術區, phone=56789, shopImg=\upload\item\shopImage\7\2018080410094723088.jpg, priority=96, createTime=Sat Aug 04 10:09:48 CST 2018, lastEditTime=Sat Aug 04 10:09:48 CST 2018, enableStatus=1, advice=null, owner=null, area=Area [areaId=1, areaName=北京, areaDesc=null, priority=null, createTime=null, lastEditTime=null], shopCategory=ShopCategory [shopCategoryId=9, shopCategoryName=奶茶, shopCategoryDesc=null, shopCategoryImg=null, priority=null, createTime=null, lastEditTime=null, parent=null]] 八月 04, 2018 11:44:37 上午 org.springframework.context.support.GenericApplicationContext doClose

Service層

接口方法

復用ShopService#getShopList


##接口實現類

ShopServiceImpl#getShopList


單元測試

因復用,之前已經單元測試通過,這里省略。


Controller層

增加 ShopListController

package com.artisan.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.artisan.o2o.dto.ShopExecution; import com.artisan.o2o.entity.Area; import com.artisan.o2o.entity.Shop; import com.artisan.o2o.entity.ShopCategory; import com.artisan.o2o.service.AreaService; import com.artisan.o2o.service.ShopCategoryService; import com.artisan.o2o.service.ShopService; import com.artisan.o2o.util.HttpServletRequestUtil;@Controller @RequestMapping("/frontend") public class ShopListController {@Autowiredprivate ShopService shopService;@Autowiredprivate AreaService areaService;@Autowiredprivate ShopCategoryService shopCategoryService;@RequestMapping(value = "/listshopspageinfo", method = RequestMethod.GET)@ResponseBodyprivate Map<String, Object> listShopsPageInfo(HttpServletRequest request) {Map<String, Object> modelMap = new HashMap<String, Object>();long parentId = HttpServletRequestUtil.getLong(request, "parentId");List<ShopCategory> shopCategoryList = null;// parentId不為空,查詢出對應parentId目錄下的全部商品目錄if (parentId != -1) {try {ShopCategory childCategory = new ShopCategory();ShopCategory parentCategory = new ShopCategory();parentCategory.setShopCategoryId(parentId);childCategory.setParent(parentCategory);shopCategoryList = shopCategoryService.getShopCategoryList(childCategory);} catch (Exception e) {modelMap.put("success", false);modelMap.put("errMsg", e.toString());}} else {// parentId為空,查詢出一級的shopCategorytry {shopCategoryList = shopCategoryService.getShopCategoryList(null);} catch (Exception e) {modelMap.put("success", false);modelMap.put("errMsg", e.toString());}}modelMap.put("shopCategoryList", shopCategoryList);List<Area> areaList = null;try {areaList = areaService.getAreaList();modelMap.put("areaList", areaList);modelMap.put("success", true);return modelMap;} catch (Exception e) {modelMap.put("success", false);modelMap.put("errMsg", e.toString());}return modelMap;}@RequestMapping(value = "/listshops", method = RequestMethod.GET)@ResponseBodyprivate Map<String, Object> listShops(HttpServletRequest request) {Map<String, Object> modelMap = new HashMap<String, Object>();int pageIndex = HttpServletRequestUtil.getInt(request, "pageIndex");int pageSize = HttpServletRequestUtil.getInt(request, "pageSize");if ((pageIndex > -1) && (pageSize > -1)) {long parentId = HttpServletRequestUtil.getLong(request, "parentId");long shopCategoryId = HttpServletRequestUtil.getLong(request, "shopCategoryId");int areaId = HttpServletRequestUtil.getInt(request, "areaId");String shopName = HttpServletRequestUtil.getString(request, "shopName");// 封裝查詢條件Shop shopCondition = compactShopCondition4Search(parentId, shopCategoryId, areaId, shopName);// 調用service層提供的方法ShopExecution se = shopService.getShopList(shopCondition, pageIndex, pageSize);modelMap.put("shopList", se.getShopList());modelMap.put("count", se.getCount());modelMap.put("success", true);} else {modelMap.put("success", false);modelMap.put("errMsg", "empty pageSize or pageIndex");}return modelMap;}private Shop compactShopCondition4Search(long parentId, long shopCategoryId, int areaId, String shopName) {Shop shopCondition = new Shop();if (parentId != -1L) {ShopCategory childCategory = new ShopCategory();ShopCategory parentCategory = new ShopCategory();parentCategory.setShopCategoryId(parentId);childCategory.setParent(parentCategory);shopCondition.setShopCategory(childCategory);}if (shopCategoryId != -1L) {ShopCategory shopCategory = new ShopCategory();shopCategory.setShopCategoryId(shopCategoryId);shopCondition.setShopCategory(shopCategory);}if (areaId != -1L) {Area area = new Area();area.setAreaId(areaId);shopCondition.setArea(area);}if (shopName != null) {shopCondition.setShopName(shopName);}// 查詢狀態為審核通過的商鋪shopCondition.setEnableStatus(1);return shopCondition;}}

單元測試

啟動tomcat,可以以debug的方式調測

分別對兩個路由方法進行測試類,訪問如下URL

http://localhost:8080/o2o/frontend/listshopspageinfohttp://localhost:8080/o2o/frontend/listshopspageinfo?parentId=5

http://localhost:8080/o2o/frontend/listshops?pageIndex=1&pageSize=3http://localhost:8080/o2o/frontend/listshops?pageIndex=1&pageSize=3&parentId=3http://localhost:8080/o2o/frontend/listshops?pageIndex=1&pageSize=3&parentId=3&shopName=咖啡

觀察返回的json數據,是否符合預期。


Github地址

代碼地址: https://github.com/yangshangwei/o2o

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的实战SSM_O2O商铺_41【前端展示】店铺列表页面Dao+Service+Controller层的实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。