SSM项目之商铺系统-前端展示系统之商铺类型列表和商铺列表展示的开发(十八)

我们现在开发前端展示系统的开发

我们先开发首页:

我们先进行预览:

首先最上面是轮播图 ,然后是一级商铺类别展示

我们分析轮播图,轮播图的轮播功能通过前台实现,我们后台要实现的就是存入轮播图的图片和信息

那么这个方法将会很简单,我们之前也创建了轮播图的表和实体类

接下来开始开发dao到controller的开发

通过接受一个HeadLine的实体类来完成了相应的查询,返回一个列表,因为可能有多个轮播图

mapper.xml:

 


 
 
  1. <!--返回可用的头条信息-->
  2. <select id="queryHeadLine" resultType="headLine">
  3. SELECT
  4. line_id,
  5. line_name,
  6. line_link,
  7. line_img,
  8. priority,
  9. enable_status,
  10. create_time,
  11. last_edit_time
  12. FROM
  13. tb_head_line
  14. <where>
  15. <if test="headLineCondition.enableStatus != null">
  16. and enable_status = #{headLineCondition.enableStatus}
  17. </if>
  18. </where>
  19. ORDER BY
  20. priority
  21. DESC
  22. </select>

接受传来的headline参数进行条件查询,并返回结果

接下来service层:

serviceImpl:


 
 
  1. @Service
  2. public class HeadLineServiceImpl implements HeadLineService{
  3. @Autowired
  4. HeadLineDao headLineDao;
  5. @Override
  6. public List<HeadLine> queryHeadLineList(HeadLine headLineCondition) {
  7. return headLineDao.queryHeadLine(headLineCondition);
  8. }
  9. }

没什么多余的处理直接调用dao层的方法获得轮播图列表

 

接下来看下商铺一级类别的展示功能实现:

DAO层:

之前已经实现过的方法

mapper.xml

这里是我们查询的mapper文件内容,我们在这里显示第一类别时就传入shopCategort为null,根据查询条件显示的就是我们的第一类别


 
 
  1. <select id="queryShopCategory" resultType="shopCategory">
  2. SELECT
  3. shop_category_id ,
  4. shop_category_name,
  5. shop_category_desc,
  6. shop_category_img,
  7. priority,
  8. create_time,
  9. last_edit_time,
  10. parent_id
  11. FROM
  12. tb_shop_category
  13. <where>
  14. <!--我们查询店铺的话都是查询二级店铺,就是有父类型店铺,一级店铺像是一个选择界面, 点击后进入二级界面-->
  15. <!--查询所有基类别显示在首页-->
  16. <if test="shopCategoryCondition== null">
  17. and parent_id IS NULL
  18. </if>
  19. <!--查询所有二级类别供我们需要时使用-->
  20. <if test="shopCategoryCondition!= null">
  21. and parent_id IS NOT NULL
  22. </if>
  23. <!--显示一级类别相同的二级类别-->
  24. <if test="shopCategoryCondition!= null and shopCategoryCondition.parent != null and shopCategoryCondition.parent.shopCategoryId != null">
  25. and parent_id=#{shopCategoryCondition.parent.shopCategoryId}
  26. </if>
  27. </where>
  28. ORDER BY priority
  29. DESC
  30. </select>

service:

serviceImpl:

并没有什么多余的操作

 

 

接下来看controller,这个controller直接交给前端轮播图和一级商铺的内容。

 


 
 
  1. package storepro.web.front;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RequestMethod;
  6. import org.springframework.web.bind.annotation.ResponseBody;
  7. import storepro.dao.HeadLineDao;
  8. import storepro.entity.HeadLine;
  9. import storepro.entity.ShopCategory;
  10. import storepro.service.HeadLineService;
  11. import storepro.service.ShopCategoryService;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. //用于处理显示前台信息的controller
  17. @Controller
  18. @RequestMapping( "/frontend")
  19. public class MainPageController {
  20. @Autowired
  21. ShopCategoryService shopCategoryService;
  22. @Autowired
  23. HeadLineService headLineService;
  24. //获取前端需要的头条信息和商品展示列表
  25. @RequestMapping(value = "/listmainpage", method = RequestMethod.GET)
  26. @ResponseBody
  27. private Map<String,Object> listMainPageInfo(){
  28. Map<String,Object> modelMap= new HashMap<String,Object>();
  29. List<ShopCategory> shopCategoryList= new ArrayList<ShopCategory>();
  30. //先获取一级目录,当传入为空时获取一级目录
  31. try {
  32. shopCategoryList= shopCategoryService.getShopCategoryList( null);
  33. modelMap.put( "shopCategoryList",shopCategoryList);
  34. } catch (Exception e){
  35. modelMap.put( "success", false);
  36. modelMap.put( "errMsg",e.getMessage());
  37. }
  38. //接下来存入头条
  39. try {
  40. HeadLine headLine = new HeadLine();
  41. headLine.setEnableStatus( 1); //获取那些状态为1的头条
  42. List<HeadLine> headLineList = headLineService.queryHeadLineList(headLine);
  43. modelMap.put( "headLineList", headLineList);
  44. } catch (Exception e){
  45. e.printStackTrace();
  46. modelMap.put( "errMsg", "取出头条失败");
  47. }
  48. modelMap.put( "success", true);
  49. return modelMap;
  50. }
  51. }

第一步:获取商铺一级类别列表,这里传入null参数才能返回一级列表

第二步:接受传入的头条

第三步:将前面的内容全部包装并送给前端

还要写一个controller返回到这个html页面

 view层:


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>我的生活 </title>
  7. <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  8. <link rel="shortcut icon" href="/storepro/favicon.ico">
  9. <meta name="apple-mobile-web-app-capable" content="yes">
  10. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  11. <link rel="stylesheet"
  12. href= "//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
  13. <link rel="stylesheet"
  14. href= "//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
  15. <link rel="stylesheet" href="../resources/css/frontend/index/index.css">
  16. </head>
  17. <body>
  18. <div class="page-group">
  19. <div class="page">
  20. <header class="bar bar-nav">
  21. <!-- <a class="button button-link button-nav pull-left" href="/demos/card" data-transition='slide-out'>
  22. <span class="icon icon-left"></span>
  23. 返回
  24. </a> -->
  25. <h1 class="title">O2O </h1>
  26. </header>
  27. <nav class="bar bar-tab">
  28. <a class="tab-item active" href="#"> <span
  29. class= "icon icon-home"> </span> <span class="tab-label">首页 </span>
  30. </a> <a class="tab-item" href="#" id='me'> <span class="icon icon-me"> </span>
  31. <span class="tab-label"></span>
  32. </a>
  33. </nav>
  34. <div class="content">
  35. <!-- 这里是页面内容区 -->
  36. <div class="swiper-container index-banner" data-space-between='10'>
  37. <div class="swiper-wrapper">
  38. <!-- <div class="swiper-slide img-wrap">
  39. <img class="banner-img" src="//gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i1/TB1n3rZHFXXXXX9XFXXXXXXXXXX_!!0-item_pic.jpg_320x320q60.jpg" alt="">
  40. </div>
  41. <div class="swiper-slide img-wrap">
  42. <img class="banner-img" src="//gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i4/TB10rkPGVXXXXXGapXXXXXXXXXX_!!0-item_pic.jpg_320x320q60.jpg" alt="">
  43. </div>
  44. <div class="swiper-slide img-wrap">
  45. <img class="banner-img" src="//gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i1/TB1kQI3HpXXXXbSXFXXXXXXXXXX_!!0-item_pic.jpg_320x320q60.jpg" alt="">
  46. </div> -->
  47. </div>
  48. <div class="swiper-pagination"> </div>
  49. </div>
  50. <div class='total-shop-button'>
  51. <a href="/storepro/frontend/shoplist" external>全部商店 </a>
  52. </div>
  53. <div class="row">
  54. <!-- <div class="col-50 shop-classify">
  55. <div class='word'>
  56. <p class='shop-title'>本期推荐</p>
  57. <p class='shop-desc'>近期相关活动、新款上市、旅游资讯</p>
  58. </div>
  59. <div class='shop-classify-img-warp'>
  60. <img class='shop-img' src="static/index/display13.png">
  61. </div>
  62. </div> -->
  63. </div>
  64. </div>
  65. </div>
  66. <!--侧边栏 TODO -->
  67. <div class="panel-overlay"> </div>
  68. <div class="panel panel-right panel-reveal" id="panel-left-demo">
  69. <div class="content-block">
  70. <p>
  71. <a href="/storepro/frontend/myrecord" class="close-panel">消费记录 </a>
  72. </p>
  73. <p>
  74. <a href="/storepro/frontend/mypoint" class="close-panel">我的积分 </a>
  75. </p>
  76. <p>
  77. <a href="/storepro/frontend/pointrecord" class="close-panel">积分兑换记录 </a>
  78. </p>
  79. <!-- Click on link with "close-panel" class will close panel -->
  80. </div>
  81. </div>
  82. </div>
  83. <script type='text/javascript'
  84. src= '//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset= 'utf-8'> </script>
  85. <script type='text/javascript'
  86. src= '//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset= 'utf-8'> </script>
  87. <script type='text/javascript'
  88. src= '//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset= 'utf-8'> </script>
  89. <script type='text/javascript' src='../resources/js/frontend/index.js'
  90. charset= 'utf-8'> </script>
  91. </body>
  92. </html>


 
 
  1. $( function() {
  2. // 定义访问后台获取头条列表以及一级商铺类别列表的URL
  3. var url = '/storepro/frontend/listmainpage';
  4. // 访问后台获取头条列表以及一级商铺类别
  5. $.getJSON(url, function (data) {
  6. if (data.success) {
  7. // 定义变量,接收后台传递过来的头条列表数据
  8. var headLineList = data.headLineList;
  9. var swiperHtml = '';
  10. // 遍历头条列表,并拼接出轮播图组
  11. headLineList.map( function (item, index) {
  12. swiperHtml += ''
  13. + '<div class="swiper-slide img-wrap">'
  14. + '<img class="banner-img" src="'+ item.lineImg + '" alt="'+ item.lineName + '">'
  15. + '</div>';
  16. });
  17. // 将轮播图组赋值给前端HTML空间
  18. $( '.swiper-wrapper').html(swiperHtml);
  19. // 设置轮播图轮换时间为1秒
  20. $( ".swiper-container").swiper({
  21. autoplay: 1000,
  22. // 用户对轮播图进行操作时,是否自动停止autoplay
  23. autoplayDisableOnInteraction: false
  24. });
  25. // 获取后台传递过来的一级商铺类别列表
  26. var shopCategoryList = data.shopCategoryList;
  27. var categoryHtml = '';
  28. // 遍历台传递过来的一级商铺类别列表 拼接出col-50 两两一行的类别
  29. shopCategoryList.map( function (item, index) {
  30. categoryHtml += ''
  31. + '<div class="col-50 shop-classify" data-category='+ item.shopCategoryId + '>'
  32. + '<div class="word">'
  33. + '<p class="shop-title">'+ item.shopCategoryName + '</p>'
  34. + '<p class="shop-desc">'+ item.shopCategoryDesc + '</p>'
  35. + '</div>'
  36. + '<div class="shop-classify-img-warp">'
  37. + '<img class="shop-img" src="'+ item.shopCategoryImg + '">'
  38. + '</div>'
  39. + '</div>';
  40. });
  41. $( '.row').html(categoryHtml);
  42. }
  43. });
  44. // 我的
  45. $( '#me').click( function () {
  46. $.openPanel( '#panel-left-demo');
  47. });
  48. // 点击特定的分类
  49. $( '.row').on( 'click', '.shop-classify', function (e) {
  50. var shopCategoryId = e.currentTarget.dataset.category;
  51. var newUrl = '/storepro/frontend/shoplist?parentId=' + shopCategoryId;
  52. window.location.href = newUrl;
  53. });
  54. });


 
 
  1. .index-banner {
  2. height: 35%;
  3. padding-bottom: 0.4rem;
  4. }
  5. .img-wrap {
  6. overflow: hidden;
  7. }
  8. .banner-img {
  9. width: 100%;
  10. height: 100%;
  11. }
  12. .total-shop-button {
  13. height: 1.5rem;
  14. line-height: 1.5rem;
  15. padding-left: 0.85rem;
  16. margin-bottom: 0.4rem;
  17. position: relative;
  18. cursor: pointer;
  19. }
  20. .total-shop-button :before {
  21. content: '';
  22. display: inline-block;
  23. position: absolute;
  24. left: 0;
  25. width: 0.15rem;
  26. height: 1.5rem;
  27. background-color: #0894ec;
  28. }
  29. .shop-classify {
  30. height: 3.3rem;
  31. padding: 0.2rem;
  32. cursor: pointer;
  33. }
  34. .shop-classify > .word {
  35. width: 65%;
  36. height: 100%;
  37. overflow: hidden;
  38. float: left;
  39. }
  40. .shop-classify > .word > p {
  41. margin: 0;
  42. }
  43. .shop-classify > .word > .shop-title {
  44. margin: 0;
  45. font-size: 0.8rem;
  46. }
  47. .shop-classify > .word > .shop-desc {
  48. margin: 0;
  49. font-size: 0.4rem;
  50. }
  51. .shop-classify > .shop-classify-img-warp {
  52. width: 30%;
  53. height: 100%;
  54. margin-left: 0.2rem;
  55. display: inline-block;
  56. }
  57. .shop-classify > .shop-classify-img-warp > .shop-img {
  58. width: 100%;
  59. height: 100%;
  60. }

接下来我们完成店铺列表页的详情开发,我们先看下店铺列表页的展示

当我们点击某个一级了类别时会显示其下的店铺种类列表和店铺详情,

这些就是店铺列表详情 ,我们可以通过点击一级商铺类别时显示所有一级店铺类别下的所有二级商铺类别,然后通过选择查出相应的店铺

注意我们还有一种情况

当点击全部商店时

 

我们要展示所有一级类别并且显示所有店铺

那么我们首先来实现点击一级类别或者全部商铺时展示的上方商铺类别的选择模块

梳理思路:

底层实现就是通过获得前端的查询条件,处理后交给dao层,通过条件获得商铺列表

dao层和service层都实现过了

我们直接讲解controller层:


 
 
  1. /*
  2. * 当我们点击某个一级类别时,我们进入到商铺列表的时候,上面还有一排供选择二级商铺类别,我们的任务就是显示这个
  3. * 还有就是直接点击全部,会显示所有商铺类别
  4. * 还需要展示地区,供选择
  5. * */
  6. @RequestMapping(value = "/listshopspageinfo", method = RequestMethod.GET)
  7. @ResponseBody
  8. private Map<String, Object> listShopsPageInfo(HttpServletRequest request) {
  9. Map<String, Object> modelMap = new HashMap<String, Object>();
  10. //设置对象传入方法
  11. long parentId = HttpServletRequestUtil.getLong(request, "parentId");
  12. List<ShopCategory> shopCategoryList = null;
  13. try {
  14. if (parentId != - 1) { //如果获取的shopCategoryId不等于-1,-1为点击全部时的显示
  15. ShopCategory shopCategory = new ShopCategory(); //
  16. ShopCategory shopCategoryParent = new ShopCategory();
  17. shopCategoryParent.setShopCategoryId(parentId);
  18. shopCategory.setParent(shopCategoryParent);
  19. //调用方法,查找相应的二级类别
  20. shopCategoryList = shopCategoryService.getShopCategoryList(shopCategory); //只传入一级类别的id即可,
  21. modelMap.put( "shopCategoryList", shopCategoryList); //存入信息
  22. } else {
  23. shopCategoryList = shopCategoryService.getShopCategoryList( null); //获取所有商品类别
  24. modelMap.put( "shopCategoryList", shopCategoryList); //存入信息
  25. }
  26. } catch (ShopOperationException e) {
  27. modelMap.put( "success", false);
  28. modelMap.put( "errMsg", e.getMessage());
  29. return modelMap;
  30. }
  31. //获取所有地区供查询
  32. List<Area> areaList = null;
  33. try {
  34. areaList = areaService.getAreaList();
  35. modelMap.put( "areaList", areaList); //存入信息
  36. } catch (Exception e) {
  37. modelMap.put( "success", false);
  38. modelMap.put( "errMsg", e.getMessage());
  39. }
  40. modelMap.put( "success", true); //成功标识
  41. return modelMap;
  42. }

我们需要的条件只有一个就是点击的商铺类别的父类的id

我们前端设置如果点击全部商品为-1,因为这个需要特殊处理

第一步:判断parentId,不为-1我们则获取相应的点击的条件查询

第二步:如果是parentId为-1,我们则传入条件为null,这样出查询出来的条件就是全部一级店铺类别显示在上方

第三步:查出当前商铺类别可选的商铺区域信息,供前端显示

 

因为还加入了新html页面我们需要控制路由转发至这个页面


view层与下面的方法相同我们一起完成

接下来我们来完成当点击一个店铺类或者相应的条件时展示的相应的店铺列表

思路梳理:

当我们点击商铺类别或者选择区域时我们显示相应类别下的商铺列表

分几种情况

当我们点击全部商品时:我们无条件查询

当我们点击一级类别时:我们通过查询parentId相等的店铺

当我们点击二级类别或者其他限定条件时:根据相应的条件进行查询

方法就是查询商铺列表,之前实现过了

我们在查询商铺列表的查询语句中的判定条件多加了一个


 
 
  1. <!--分页查询店铺列表 ,可选条件有店铺名,店铺状态,店铺类别,区域id,owner-->
  2. <select id="queryShopList" resultMap="shopMap" >
  3. SELECT
  4. s.shop_id,
  5. s.shop_name,
  6. s.shop_desc,
  7. s.shop_addr,
  8. s.phone,
  9. s.shop_img,
  10. s.priority,
  11. s.create_time,
  12. s.last_edit_time,
  13. s.enable_status,
  14. s.advice,
  15. a.area_id,
  16. a.area_name,
  17. sc.shop_category_id,
  18. sc.shop_category_name
  19. FROM
  20. tb_shop s,
  21. tb_area a,
  22. tb_shop_category sc
  23. <where>
  24. <if test="shopCondition.shopCategory!=null and shopCondition.shopCategory.shopCategoryId!=null">
  25. and s.shop_category_id=#{shopCondition.shopCategory.shopCategoryId}
  26. </if>
  27. <if test="shopCondition.area!=null and shopCondition.area.areaId!=null">
  28. and s.area_id=#{shopCondition.area.areaId}
  29. </if>
  30. <if test="shopCondition.shopName!=null">
  31. and s.shop_name like '%${shopCondition.shopName}%'
  32. </if>
  33. <if test="shopCondition.enableStatus!=null">
  34. and s.enable_status=#{shopCondition.enableStatus}
  35. </if>
  36. <if test="shopCondition.owner!=null and shopCondition.owner.userId!=null">
  37. and s.owner_id=#{shopCondition.owner.userId}
  38. </if>
  39. <!--查出当前商铺同类型的商铺-->
  40. <!--比如美食下面有两个种类,是大排档和火锅,当我们在主页点击美食这个图片的时候我们要显示大排档和火锅下的所有商铺
  41. -->
  42. <if test="shopCondition.shopCategory!=null and shopCondition.shopCategory.parent!=null and shopCondition.shopCategory.parent.shopCategoryId != null">
  43. and s.shop_category_id in (SELECT shop_category_id from tb_shop_category
  44. WHERE parent_id=#{shopCondition.shopCategory.parent.shopCategoryId} )
  45. </if>
  46. AND s.area_id=a.area_id
  47. AND s.shop_category_id=sc.shop_category_id
  48. </where>
  49. ORDER BY
  50. s.priority
  51. DESC
  52. limit #{rowIndex},#{pageSize};
  53. </select>

 
 
  1. <!--查出当前商铺同类型的商铺-->
  2. <!--比如美食下面有两个种类,是大排档和火锅,当我们在主页点击美食这个图片的时候我们要显示大排档和火锅下的所有商铺
  3. -->
  4. <if test="shopCondition.shopCategory!=null and shopCondition.shopCategory.parent!=null and shopCondition.shopCategory.parent.shopCategoryId != null">
  5. and s.shop_category_id in (SELECT shop_category_id from tb_shop_category
  6. WHERE parent_id=#{shopCondition.shopCategory.parent.shopCategoryId} )
  7. </if>

 这句说明就是点击一级类别查询底下的所有商铺类别

controller层实现:


 
 
  1. /*
  2. * 根据传入的条件查询店铺
  3. * */
  4. @RequestMapping(value = "/listshops", method = RequestMethod.GET)
  5. @ResponseBody
  6. private Map<String, Object> listShops(HttpServletRequest request) throws UnsupportedEncodingException {
  7. Map<String, Object> modelMap = new HashMap<String, Object>();
  8. //先获取前台传来的数据()
  9. //获取页码
  10. int pageIndex = HttpServletRequestUtil.getInt(request, "pageIndex");
  11. int pageSize = HttpServletRequestUtil.getInt(request, "pageSize");
  12. try {
  13. if ((pageIndex > - 1) && (pageSize > - 1)){
  14. //获取组合查询条件
  15. long parentId = HttpServletRequestUtil.getLong(request, "parentId");
  16. long shopCategoryId = HttpServletRequestUtil.getLong(request, "shopCategoryId");
  17. int areaId = HttpServletRequestUtil.getInt(request, "areaId");
  18. String shopName=HttpServletRequestUtil.getString(request, "shopName");
  19. // 封装查询条件
  20. Shop shopCondition = compactShopCondition4Search(parentId, shopCategoryId, areaId, shopName);
  21. // 调用service层提供的方法,获取条件查询的语句
  22. ShopExecution se = shopService.getShopList(shopCondition, pageIndex, pageSize);
  23. modelMap.put( "shopList", se.getShopList()); //交给前端
  24. modelMap.put( "count", se.getCount());
  25. modelMap.put( "success", true);
  26. } else {
  27. modelMap.put( "success", false);
  28. modelMap.put( "errMsg", "empty pageSize or pageIndex");
  29. }
  30. } catch (Exception e){
  31. modelMap.put( "success" , false);
  32. modelMap.put( "errMsg" ,e.getMessage());
  33. }
  34. return modelMap;
  35. }
  36. private Shop compactShopCondition4Search(long parentId, long shopCategoryId, int areaId, String shopName) throws UnsupportedEncodingException {
  37. Shop shopCondition= new Shop();
  38. if (parentId>- 1){
  39. ShopCategory shopCategory= new ShopCategory();
  40. ShopCategory shopCategoryParent= new ShopCategory();
  41. shopCategoryParent.setShopCategoryId(parentId);
  42. shopCategory.setParent(shopCategoryParent);
  43. shopCondition.setShopCategory(shopCategory);
  44. }
  45. //判断shopCategoryId如果这个参数有值,代表我们通过二级商铺类型查找店铺
  46. if (shopCategoryId>- 1){
  47. ShopCategory shopCategory= new ShopCategory();
  48. shopCategory.setShopCategoryId(shopCategoryId);
  49. shopCondition.setShopCategory(shopCategory);
  50. }
  51. //判断areaid是否有值
  52. if (areaId>- 1){
  53. Area area = new Area();
  54. area.setAreaId(areaId);
  55. shopCondition.setArea(area);
  56. }
  57. //判断shopName是否有值
  58. if (shopName!= null){
  59. shopName= new String(shopName.getBytes( "ISO-8859-1"), "UTF-8");
  60. shopCondition.setShopName(shopName);
  61. }
  62. // 查询状态为审核通过的商铺
  63. shopCondition.setEnableStatus( 1);
  64. return shopCondition;
  65. }
  66. }

我们要着重说拼装查询条件的方法:

我们这里需要置查询条件为空才能查所有商铺,因为在mapper文件中的判断中如果一个condition对象的需要查询条件的属性都为空那么会直接无条件查询(看mapper文件可知)

还有点击一级类别时,此时只能设置一个店铺类别id为空的但是parent为一级类别的对象传入才能查出(看mapper文件可知)

最后就是我们是使用GET方法获取数据,然而当我通过shopName查询时得到了乱码,我们需要进一步设置

先获得前端传来的字符,此时是乱码

然后通过 shopName= new String(shopName.getBytes("ISO-8859-1"), "UTF-8");字符格式转换为utf-8格式

 

商铺列表和商铺类别列表的View层:


 
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>商店列表 </title>
  7. <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  8. <link rel="shortcut icon" href="/favicon.ico">
  9. <meta name="apple-mobile-web-app-capable" content="yes">
  10. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  11. <link rel="stylesheet"
  12. href= "//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
  13. <link rel="stylesheet"
  14. href= "//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">
  15. <link rel="stylesheet" href="../resources/css/frontend/shoplist.css">
  16. </head>
  17. <body>
  18. <div class="page-group">
  19. <div class="page">
  20. <header class="bar bar-nav">
  21. <a class="button button-link button-nav pull-left" external
  22. href= "index" data-transition= 'slide-out'> <span
  23. class= "icon icon-left"> </span> 返回
  24. </a>
  25. <h1 class="title">商店列表 </h1>
  26. </header>
  27. <div class="bar bar-header-secondary">
  28. <div class="searchbar">
  29. <a class="searchbar-cancel">取消 </a>
  30. <!-- 搜索栏 -->
  31. <div class="search-input">
  32. <label class="icon icon-search" for="search"> </label> <input
  33. type= "search" id= 'search' placeholder= '输入关键字...' />
  34. </div>
  35. </div>
  36. </div>
  37. <nav class="bar bar-tab">
  38. <a class="tab-item" href="/storepro/frontend/index" external> <span
  39. class= "icon icon-home"> </span> <span class="tab-label">首页 </span>
  40. </a> <a class="tab-item" href="#" id="me"> <span
  41. class= "icon icon-me"> </span> <span class="tab-label"></span>
  42. </a>
  43. </nav>
  44. <div class="content infinite-scroll infinite-scroll-bottom"
  45. data-distance= "100">
  46. <!-- 类别列表展示区 -->
  47. <div class="shoplist-button-div" id="shoplist-search-div">
  48. <!-- <a href="#" class="button">所有货物</a>
  49. <a href="#" class="button">吃的</a>
  50. <a href="#" class="button">喝的</a>
  51. <a href="#" class="button">Usual Button 1</a>
  52. <a href="#" class="button">Usual Button 1</a>
  53. <a href="#" class="button">Usual Button 1</a> -->
  54. </div>
  55. <div class="select-wrap">
  56. <!-- 区域列表展示区 -->
  57. <select class="select" id="area-search"> </select>
  58. </div>
  59. <!-- 店铺列表在此添加 -->
  60. <div class="list-div shop-list">
  61. <!-- <div class="card">
  62. <div class="card-header">传统火锅店</div>
  63. <div class="card-content">
  64. <div class="list-block media-list">
  65. <ul>
  66. <li class="item-content">
  67. <div class="item-media">
  68. <img src="http://gqianniu.alicdn.com/bao/uploaded/i4//tfscom/i3/TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg" width="44">
  69. </div>
  70. <div class="item-inner">
  71. <div class="item-subtitle"></div>
  72. </div>
  73. </li>
  74. </ul>
  75. </div>
  76. </div>
  77. <div class="card-footer">
  78. <span>2015/01/15</span>
  79. <span>5 评论</span>
  80. </div>
  81. </div> -->
  82. </div>
  83. <div class="infinite-scroll-preloader">
  84. <div class="preloader"> </div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. <!--侧边栏 -->
  90. <div class="panel-overlay"> </div>
  91. <div class="panel panel-right panel-reveal" id="panel-right-demo">
  92. <div class="content-block">
  93. <p>
  94. <a href="/storepro/local/accountbind?usertype=1" class="close-panel">绑定帐号 </a>
  95. </p>
  96. <p>
  97. <a href="/storepro/local/changepsw?usertype=1" class="close-panel">修改密码 </a>
  98. </p>
  99. <p>
  100. <a href="/storepro/frontend/myrecord" class="close-panel">消费记录 </a>
  101. </p>
  102. <p>
  103. <a href="/storepro/frontend/mypoint" class="close-panel">我的积分 </a>
  104. </p>
  105. <p>
  106. <a href="/storepro/frontend/pointrecord" class="close-panel">兑换记录 </a>
  107. </p>
  108. <p>
  109. <a href="#" usertype="1" class="close-panel" id="log-out">登出系统 </a>
  110. </p>
  111. <!-- Click on link with "close-panel" class will close panel -->
  112. </div>
  113. </div>
  114. <script type='text/javascript'
  115. src= '//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset= 'utf-8'> </script>
  116. <script type='text/javascript'
  117. src= '//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset= 'utf-8'> </script>
  118. <script type='text/javascript'
  119. src= '//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset= 'utf-8'> </script>
  120. <script type='text/javascript' src='../resources/js/common/common.js'
  121. charset= 'utf-8'> </script>
  122. <script type='text/javascript'
  123. src= '../resources/js/frontend/shoplist.js' charset= 'utf-8'> </script>
  124. <script type='text/javascript' src='../resources/js/local/login.js'
  125. charset= 'utf-8'> </script>
  126. </body>
  127. </html>


 
 
  1. $( function() {
  2. var loading = false;
  3. // 分页允许返回的最大条数,超过此数则禁止访问后台
  4. var maxItems = 999;
  5. // 一页返回的最大条数
  6. var pageSize = 3;
  7. // 获取店铺列表的URL
  8. var listUrl = '/storepro/frontend/listshops';
  9. // 获取店铺类别列表以及区域列表的URL
  10. var searchDivUrl = '/storepro/frontend/listshopspageinfo';
  11. // 页码
  12. var pageNum = 1;
  13. // 从地址栏URL里尝试获取parent shop category id.
  14. var parentId = getQueryString( 'parentId');
  15. var areaId = '';
  16. var shopCategoryId = '';
  17. var shopName = '';
  18. // 渲染出店铺类别列表以及区域列表以供搜索
  19. getSearchDivData();
  20. // 预先加载10条店铺信息
  21. addItems(pageSize, pageNum);
  22. /**
  23. * 获取店铺类别列表以及区域列表信息
  24. *
  25. * @returns
  26. */
  27. function getSearchDivData() {
  28. // 如果传入了parentId,则取出此一级类别下面的所有二级类别
  29. var url = searchDivUrl + '?' + 'parentId=' + parentId;
  30. $
  31. .getJSON(
  32. url,
  33. function(data) {
  34. if (data.success) {
  35. // 获取后台返回过来的店铺类别列表
  36. var shopCategoryList = data.shopCategoryList;
  37. var html = '';
  38. html += '<a href="#" class="button" data-category-id=""> 全部类别 </a>';
  39. // 遍历店铺类别列表,拼接出a标签集
  40. shopCategoryList
  41. .map( function(item, index) {
  42. html += '<a href="#" class="button" data-category-id='
  43. + item.shopCategoryId
  44. + '>'
  45. + item.shopCategoryName
  46. + '</a>';
  47. });
  48. // 将拼接好的类别标签嵌入前台的html组件里
  49. $( '#shoplist-search-div').html(html);
  50. var selectOptions = '<option value="">全部街道</option>';
  51. // 获取后台返回过来的区域信息列表
  52. var areaList = data.areaList;
  53. // 遍历区域信息列表,拼接出option标签集
  54. areaList.map( function(item, index) {
  55. selectOptions += '<option value="'
  56. + item.areaId + '">'
  57. + item.areaName + '</option>';
  58. });
  59. // 将标签集添加进area列表里
  60. $( '#area-search').html(selectOptions);
  61. }
  62. });
  63. }
  64. /**
  65. * 获取分页展示的店铺列表信息
  66. *
  67. * @param pageSize
  68. * @param pageIndex
  69. * @returns
  70. */
  71. function addItems(pageSize, pageIndex) {
  72. // 拼接出查询的URL,赋空值默认就去掉这个条件的限制,有值就代表按这个条件去查询
  73. var url = listUrl + '?' + 'pageIndex=' + pageIndex + '&pageSize='
  74. + pageSize + '&parentId=' + parentId + '&areaId=' + areaId
  75. + '&shopCategoryId=' + shopCategoryId + '&shopName=' + shopName;
  76. // 设定加载符,若还在后台取数据则不能再次访问后台,避免多次重复加载
  77. loading = true;
  78. // 访问后台获取相应查询条件下的店铺列表
  79. $.getJSON(url, function(data) {
  80. if (data.success) {
  81. // 获取当前查询条件下店铺的总数
  82. maxItems = data.count;
  83. var html = '';
  84. // 遍历店铺列表,拼接出卡片集合
  85. data.shopList.map( function(item, index) {
  86. html += '' + '<div class="card" data-shop-id="'
  87. + item.shopId + '">' + '<div class="card-header">'
  88. + item.shopName + '</div>'
  89. + '<div class="card-content">'
  90. + '<div class="list-block media-list">' + '<ul>'
  91. + '<li class="item-content">'
  92. + '<div class="item-media">' + '<img src="'
  93. + item.shopImg + '" width="44">' + '</div>'
  94. + '<div class="item-inner">'
  95. + '<div class="item-subtitle">' + item.shopDesc
  96. + '</div>' + '</div>' + '</li>' + '</ul>'
  97. + '</div>' + '</div>' + '<div class="card-footer">'
  98. + '<p class="color-gray">'
  99. + new Date(item.lastEditTime).Format( "yyyy-MM-dd")
  100. + '更新</p>' + '<span>点击查看</span>' + '</div>'
  101. + '</div>';
  102. });
  103. // 将卡片集合添加到目标HTML组件里
  104. $( '.list-div').append(html);
  105. // 获取目前为止已显示的卡片总数,包含之前已经加载的
  106. var total = $( '.list-div .card').length;
  107. // 若总数达到跟按照此查询条件列出来的总数一致,则停止后台的加载
  108. if (total >= maxItems) {
  109. // 隐藏提示符
  110. $( '.infinite-scroll-preloader').hide();
  111. } else {
  112. $( '.infinite-scroll-preloader').show();
  113. }
  114. // 否则页码加1,继续load出新的店铺
  115. pageNum += 1;
  116. // 加载结束,可以再次加载了
  117. loading = false;
  118. // 刷新页面,显示新加载的店铺
  119. $.refreshScroller();
  120. }
  121. });
  122. }
  123. // 下滑屏幕自动进行分页搜索
  124. $( document).on( 'infinite', '.infinite-scroll-bottom', function() {
  125. if (loading)
  126. return;
  127. addItems(pageSize, pageNum);
  128. });
  129. // 点击店铺的卡片进入该店铺的详情页
  130. $( '.shop-list').on( 'click', '.card', function(e) {
  131. var shopId = e.currentTarget.dataset.shopId;
  132. window.location.href = '/storepro/frontend/shopdetail?shopId=' + shopId;
  133. });
  134. // 选择新的店铺类别之后,重置页码,清空原先的店铺列表,按照新的类别去查询
  135. $( '#shoplist-search-div').on(
  136. 'click',
  137. '.button',
  138. function(e) {
  139. if (parentId) { // 如果传递过来的是一个父类下的子类
  140. shopCategoryId = e.target.dataset.categoryId;
  141. // 若之前已选定了别的category,则移除其选定效果,改成选定新的
  142. if ($(e.target).hasClass( 'button-fill')) {
  143. $(e.target).removeClass( 'button-fill');
  144. shopCategoryId = '';
  145. } else {
  146. $(e.target).addClass( 'button-fill').siblings()
  147. .removeClass( 'button-fill');
  148. }
  149. // 由于查询条件改变,清空店铺列表再进行查询
  150. $( '.list-div').empty();
  151. // 重置页码
  152. pageNum = 1;
  153. addItems(pageSize, pageNum);
  154. } else { // 如果传递过来的父类为空,则按照父类查询
  155. parentId = e.target.dataset.categoryId;
  156. if ($(e.target).hasClass( 'button-fill')) {
  157. $(e.target).removeClass( 'button-fill');
  158. parentId = '';
  159. } else {
  160. $(e.target).addClass( 'button-fill').siblings()
  161. .removeClass( 'button-fill');
  162. }
  163. // 由于查询条件改变,清空店铺列表再进行查询
  164. $( '.list-div').empty();
  165. // 重置页码
  166. pageNum = 1;
  167. addItems(pageSize, pageNum);
  168. parentId = '';
  169. }
  170. });
  171. // 需要查询的店铺名字发生变化后,重置页码,清空原先的店铺列表,按照新的名字去查询
  172. $( '#search').on( 'change', function(e) {
  173. shopName = e.target.value;
  174. $( '.list-div').empty();
  175. pageNum = 1;
  176. addItems(pageSize, pageNum);
  177. });
  178. // 区域信息发生变化后,重置页码,清空原先的店铺列表,按照新的区域去查询
  179. $( '#area-search').on( 'change', function() {
  180. areaId = $( '#area-search').val();
  181. $( '.list-div').empty();
  182. pageNum = 1;
  183. addItems(pageSize, pageNum);
  184. });
  185. // 点击后打开右侧栏
  186. $( '#me').click( function() {
  187. $.openPanel( '#panel-right-demo');
  188. });
  189. // 初始化页面
  190. $.init();
  191. });


 
 
  1. .infinite-scroll-preloader {
  2. margin-top: - 5px;
  3. }
  4. .shoplist-button-div {
  5. margin: 0 . 3rem;
  6. }
  7. .shoplist-button-div > .button {
  8. width: 30%;
  9. height: 1.5rem;
  10. line-height: 1.5rem;
  11. display: inline-block;
  12. margin: 1%;
  13. overflow: hidden;
  14. }
  15. .select-wrap {
  16. margin: 0 . 5rem;
  17. }
  18. .select {
  19. border: 1px solid #0894ec;
  20. color: #0894ec;
  21. background-color: #efeff4;
  22. width: 100%;
  23. height: 1.5rem;
  24. font-size: . 7rem;
  25. }

 

 

  •                     <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count"></span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/Sunmeok">
                    <img src="https://profile.csdnimg.cn/7/A/E/3_sunmeok" class="avatar_pic" username="Sunmeok">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/2x/2.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/Sunmeok" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">Sunmeok</a></span>
                                            </div>
                    <div class="text"><span>发布了126 篇原创文章</span> · <span>获赞 27</span> · <span>访问量 7万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=Sunmeok" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值