一、分页查询:

1.1 前台:

  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  6. <title>产品列表页</title>
  7. <link rel="icon" href="/static/search/assets/img/favicon.ico">
  8. <link rel="stylesheet" type="text/css" href="/static/search/css/webbase.css" />
  9. <link rel="stylesheet" type="text/css" href="/static/search/css/pages-list.css" />
  10. <link rel="stylesheet" type="text/css" href="/static/search/css/widget-cartPanelView.css" />
  11. <style>
  12. #chooseCategory{
  13. display: none;
  14. }
  15. .dotted{
  16. display: none;
  17. }
  18. </style>
  19. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  20. <script>
  21. //1. 向字符串类扩展方法
  22. String.prototype.contains=function(str){
  23. return this.indexOf(str) > -1;
  24. }
  25. //2. 关键字查询
  26. function search(){
  27. drawPageNav()
  28. location.href = replaceParamVal(location.href,"keywords",$("#keywords").val());
  29. }
  30. //3. 添加分类
  31. function addCategory(v){
  32. //在location.href中添加分类字段
  33. drawPageNav()
  34. location.href = replaceParamVal(location.href,"category",v);
  35. return false;
  36. }
  37. //4. 显示分类面板,隐藏面包屑导航中的分类
  38. // function hideCategory(v){
  39. // $(v).css("display","none");
  40. // categoryPanel.css("display","block");
  41. // }
  42. //5. 添加品牌
  43. function addBrand(v) {
  44. drawPageNav()
  45. location.href = replaceParamVal(location.href,"brand",v);
  46. return false;
  47. }
  48. //6. 添加规格
  49. function addSpec(specText,optionName){
  50. let val = (specText + ":" + optionName);
  51. drawPageNav()
  52. location.href = replaceParamVal(location.href,"spec",val,true);
  53. return false;
  54. }
  55. //7. 添加价格区间
  56. function addPrice(price){
  57. drawPageNav()
  58. location.href = replaceParamVal(location.href,"price",price);
  59. return false;
  60. }
  61. //8. 排序价格
  62. function addSort(sortField,sortOrder){ //参数1:排序字段 参数2:排序升序(asc)还是降序(desc)
  63. drawPageNav()
  64. location.href = replaceParamVal(location.href,"sort",sortOrder + ":" + sortField);
  65. return false;
  66. }
  67. //9. 分页查询
  68. function findByPage(p){
  69. drawPageNav();
  70. location.href = replaceParamVal(location.href,"page",p);
  71. return false;
  72. }
  73. $(function(){
  74. drawPageNav();
  75. })
  76. /**
  77. * 功能: 绘制按钮导航
  78. * 参数:
  79. * 返回值:
  80. * 时间: 2021/8/5 15:10
  81. */
  82. function drawPageNav(){
  83. //0. 定义代表前后省略号的变量
  84. let firstDot = true;
  85. let lastDot = true;
  86. //1. 得到当前页
  87. let page = [[${param.page == null ? 1 : param.page}]]
  88. //2. 得到总页数
  89. let totalPage = [[${resultMap.totalPage}]]
  90. //3. 定义首页和尾页变量
  91. let firstPage = 1;
  92. let lastPage = totalPage;
  93. //4. 根据情况得到首页与尾页
  94. if(totalPage > 5){
  95. if(page <= 3){
  96. lastPage = 5;
  97. firstDot = false;
  98. }else if(page >= totalPage - 2){
  99. firstPage = totalPage - 4;
  100. lastDot = false;
  101. }else{
  102. firstPage = page - 2;
  103. lastPage = page + 2;
  104. }
  105. }else{
  106. firstDot = false;
  107. lastDot = false;
  108. }
  109. //5. 根据首页与尾页遍历得到分页导航
  110. //5.1 定义最终生成的标签字符串
  111. let info = "";
  112. for(let i = firstPage;i <= lastPage; i++){
  113. info += "<li class="+ (i == page ? 'active' : '') +">";
  114. info += "<a onclick=findByPage("+i+")>" + i + "</a>";
  115. info += "</li>";
  116. }
  117. //6. 为pageNav导航层赋值
  118. $($(".page ul li")[1]).after(info);
  119. //7. 动态生成省略号
  120. $(".dotted").css("display","none");
  121. if(firstDot){
  122. $("#first").css("display","inline-block");
  123. }
  124. if(lastDot){
  125. $("#last").css("display","inline-block");
  126. }
  127. }
  128. /**
  129. * 功能:路径替换函数
  130. * @param url 目前的url
  131. * @param paramName 需要替换的参数属性名
  132. * @param replaceVal 需要替换的参数的新属性值
  133. * @param forceAdd 该参数是否可以重复查询(spec=网络:4G&spec=机身内存:32G),即一次可以查询多个规格
  134. * @returns {string} 替换或添加后的url
  135. */
  136. function replaceParamVal(url, paramName, replaceVal,forceAdd=false) {
  137. let oUrl = decodeURI(url.toString());
  138. let nUrl = "";
  139. if (oUrl.contains(paramName+"=")) {
  140. let split = replaceVal.toString().split(":");
  141. let str = paramName+"="+split[0];
  142. if( forceAdd && !oUrl.contains(str)) { //第一次时向url添加内容
  143. if (oUrl.contains("?")) {
  144. nUrl = oUrl + "&" + paramName + "=" + replaceVal;
  145. } else {
  146. nUrl = oUrl + "?" + paramName + "=" + replaceVal;
  147. }
  148. } else {
  149. // /category=手机/ig
  150. if(paramName.startsWith("spec")){ //替换规格内容
  151. let re = eval('/(' + str + ':)([^&]*)/gi');
  152. nUrl = oUrl.replace(re, str + ':' + split[1]);
  153. } else{ //替换除规格外的其它内容
  154. let re = eval('/(' + paramName + '=)([^&]*)/gi');
  155. nUrl = oUrl.replace(re, paramName + '=' + replaceVal);
  156. }
  157. }
  158. } else {
  159. // http://localhost:9001/student/list?username=aaa&pwd=123
  160. if (oUrl.contains("?")) { //包含?
  161. nUrl = oUrl + "&" + paramName + "=" + replaceVal;
  162. } else { //不包含?
  163. nUrl = oUrl + "?" + paramName + "=" + replaceVal;
  164. }
  165. }
  166. return nUrl;
  167. }
  168. </script>
  169. </head>
  170. <body>
  171. <!-- 头部栏位 -->
  172. <!--页面顶部-->
  173. <div id="nav-bottom">
  174. <!--顶部-->
  175. <div class="nav-top">
  176. <div class="top">
  177. <div class="py-container">
  178. <div class="shortcut">
  179. <ul class="fl">
  180. <li class="f-item">泽易购欢迎您!</li>
  181. <li class="f-item">
  182. <a href="/static/search/login.html" target="_blank">登录</a> 
  183. <span><a href="/static/search/register.html" target="_blank">免费注册</a></span></li>
  184. </ul>
  185. <ul class="fr">
  186. <li class="f-item">我的订单</li>
  187. <li class="f-item space"></li>
  188. <li class="f-item">
  189. <a href="/static/search/home.html" target="_blank">我的泽易购</a>
  190. </li>
  191. <li class="f-item space"></li>
  192. <li class="f-item">泽易购会员</li>
  193. <li class="f-item space"></li>
  194. <li class="f-item">企业采购</li>
  195. <li class="f-item space"></li>
  196. <li class="f-item">关注泽易购</li>
  197. <li class="f-item space"></li>
  198. <li class="f-item" id="service">
  199. <span>客户服务</span>
  200. <ul class="service">
  201. <li>
  202. <a href="/static/search/cooperation.html" target="_blank">合作招商</a>
  203. </li>
  204. <li>
  205. <a href="/static/search/shoplogin.html" target="_blank">商家后台</a>
  206. </li>
  207. <li>
  208. <a href="/static/search/cooperation.html" target="_blank">合作招商</a>
  209. </li>
  210. <li>
  211. <a href="#">商家后台</a>
  212. </li>
  213. </ul>
  214. </li>
  215. <li class="f-item space"></li>
  216. <li class="f-item">网站导航</li>
  217. </ul>
  218. </div>
  219. </div>
  220. </div>
  221. <!--头部-->
  222. <div class="header">
  223. <div class="py-container">
  224. <div class="yui3-g Logo">
  225. <div class="yui3-u Left logoArea">
  226. <a class="logo-bd" title="泽易购" href="/static/search/JD-index.html" target="_blank"></a>
  227. </div>
  228. <div class="yui3-u Center searchArea">
  229. <div class="search">
  230. <form class="sui-form form-inline" >
  231. <!--searchAutoComplete-->
  232. <div class="input-append">
  233. <input type="text" th:value="${vo.keywords}" id="keywords" class="input-error input-xxlarge" />
  234. <input class="sui-btn btn-xlarge btn-danger" type="button" onclick="search()" value="搜索">
  235. </div>
  236. </form>
  237. </div>
  238. <div class="hotwords">
  239. <ul>
  240. <li class="f-item">泽易购首发</li>
  241. <li class="f-item">亿元优惠</li>
  242. <li class="f-item">9.9元团购</li>
  243. <li class="f-item">每满99减30</li>
  244. <li class="f-item">亿元优惠</li>
  245. <li class="f-item">9.9元团购</li>
  246. <li class="f-item">办公用品</li>
  247. </ul>
  248. </div>
  249. </div>
  250. <div class="yui3-u Right shopArea">
  251. <div class="fr shopcar">
  252. <div class="show-shopcar" id="shopcar">
  253. <span class="car"></span>
  254. <a class="sui-btn btn-default btn-xlarge" href="/static/search/cart.html" target="_blank">
  255. <span>我的购物车</span>
  256. <i class="shopnum">0</i>
  257. </a>
  258. <div class="clearfix shopcarlist" id="shopcarlist" style="display:none">
  259. <p>"啊哦,你的购物车还没有商品哦!"</p>
  260. <p>"啊哦,你的购物车还没有商品哦!"</p>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. <div class="yui3-g NavList">
  267. <div class="yui3-u Left all-sort">
  268. <h4>全部商品分类</h4>
  269. </div>
  270. <div class="yui3-u Center navArea">
  271. <ul class="nav">
  272. <li class="f-item">服装城</li>
  273. <li class="f-item">美妆馆</li>
  274. <li class="f-item">品优超市</li>
  275. <li class="f-item">全球购</li>
  276. <li class="f-item">闪购</li>
  277. <li class="f-item">团购</li>
  278. <li class="f-item">有趣</li>
  279. <li class="f-item">
  280. <a href="/static/search/seckill-index.html" target="_blank">秒杀</a>
  281. </li>
  282. </ul>
  283. </div>
  284. <div class="yui3-u Right"></div>
  285. </div>
  286. </div>
  287. </div>
  288. </div>
  289. </div>
  290. <!--list-content-->
  291. <div class="main">
  292. <div class="py-container">
  293. <!--bread-->
  294. <div class="bread">
  295. <ul class="fl sui-breadcrumb">
  296. <li>
  297. <a href="#">全部结果
  298. 总共:<span th:text="${resultMap.total}"/>
  299. </a>
  300. </li>
  301. <li class="active">智能手机</li>
  302. </ul>
  303. <ul class="tags-choose" id="chooseCategory">
  304. <li class="tag">商品分类:<span></span><i class="sui-icon icon-tb-close"
  305. onclick="hideCategory(this.parentNode.parentNode)"></i></li>
  306. </ul>
  307. <div class="clearfix"></div>
  308. </div>
  309. <!--selector-->
  310. <div class="clearfix selector">
  311. <div class="type-wrap">
  312. <div class="fl key">商品分类</div>
  313. <div class="fl value">
  314. <a href="#" th:each="category : ${resultMap.categoryList}"
  315. th:onclick="addCategory([[${category}]])">[[${category}]] </a>
  316. </div>
  317. <div class="fl ext"></div>
  318. </div>
  319. <div class="type-wrap logo">
  320. <div class="fl key brand">品牌</div>
  321. <div class="value logos">
  322. <ul class="logo-list">
  323. <!--1.显示品牌-->
  324. <li th:each="brand : ${resultMap.brandList}" th:align="center">
  325. <a href="#" th:onclick="addBrand([[${brand.text}]])">[[${brand.text}]]</a>
  326. </li>
  327. </ul>
  328. </div>
  329. </div>
  330. <!--2.显示规格列表-->
  331. <div class="type-wrap" th:each="spec,stat : ${resultMap.specList}">
  332. <div class="fl key">[[${spec.text}]]</div>
  333. <div class="fl value">
  334. <ul class="type-list">
  335. <li th:each="option : ${spec.options}">
  336. <a th:onclick="addSpec([[${spec.text}]],[[${option.optionName}]])">
  337. [[${option.optionName}]]</a>
  338. </li>
  339. </ul>
  340. </div>
  341. <div class="fl ext"></div>
  342. </div>
  343. <div class="type-wrap">
  344. <div class="fl key">价格</div>
  345. <div class="fl value">
  346. <ul class="type-list">
  347. <li>
  348. <a onclick="addPrice('0_500')">0-500元</a>
  349. </li>
  350. <li>
  351. <a onclick="addPrice('500_1000')">500-1000元</a>
  352. </li>
  353. <li>
  354. <a onclick="addPrice('1000_1500')">1000-1500元</a>
  355. </li>
  356. <li>
  357. <a onclick="addPrice('1500_2000')">1500-2000元</a>
  358. </li>
  359. <li>
  360. <a onclick="addPrice('2000_3000')">2000-3000元 </a>
  361. </li>
  362. <li>
  363. <a onclick="addPrice('3000_*')">3000元以上</a>
  364. </li>
  365. </ul>
  366. </div>
  367. <div class="fl ext">
  368. </div>
  369. </div>
  370. <div class="type-wrap">
  371. <div class="fl key">更多筛选项</div>
  372. <div class="fl value">
  373. <ul class="type-list">
  374. <li>
  375. <a>特点</a>
  376. </li>
  377. <li>
  378. <a>系统</a>
  379. </li>
  380. <li>
  381. <a>手机内存 </a>
  382. </li>
  383. <li>
  384. <a>单卡双卡</a>
  385. </li>
  386. <li>
  387. <a>其他</a>
  388. </li>
  389. </ul>
  390. </div>
  391. <div class="fl ext">
  392. </div>
  393. </div>
  394. </div>
  395. <!--details-->
  396. <div class="details">
  397. <div class="sui-navbar">
  398. <div class="navbar-inner filter">
  399. <ul class="sui-nav">
  400. <li class="active">
  401. <a href="#">综合</a>
  402. </li>
  403. <li>
  404. <a href="#">销量</a>
  405. </li>
  406. <li>
  407. <a href="#">新品</a>
  408. </li>
  409. <li>
  410. <a href="#">评价</a>
  411. </li>
  412. <li>
  413. <a href="#" onclick="addSort('price','asc')">价格↑</a>
  414. </li>
  415. <li>
  416. <a href="#" onclick="addSort('price','desc')">价格↓</a>
  417. </li>
  418. </ul>
  419. </div>
  420. </div>
  421. <div class="goods-list">
  422. <ul class="yui3-g">
  423. <li class="yui3-u-1-5" th:each="result : ${resultMap.rows}">
  424. <div class="list-wrap">
  425. <div class="p-img">
  426. <a href="#" target="_blank">
  427. <img th:src="${result.image}" /></a>
  428. </div>
  429. <div class="price">
  430. <strong>
  431. <em>¥</em>
  432. <i th:text="${result.price}"></i>
  433. </strong>
  434. </div>
  435. <div class="attr">
  436. <em th:utext="${result.title}"></em>
  437. </div>
  438. <div class="cu">
  439. <em></em>
  440. </div>
  441. <div class="commit">
  442. <i class="command">已有2000人评价</i>
  443. </div>
  444. <div class="operate">
  445. <a href="/static/search/success-cart.html" target="_blank" class="sui-btn btn-bordered btn-danger">加入购物车</a>
  446. <a href="javascript:void(0);" class="sui-btn btn-bordered">对比</a>
  447. <a href="javascript:void(0);" class="sui-btn btn-bordered">关注</a>
  448. </div>
  449. </div>
  450. </li>
  451. </ul>
  452. </div>
  453. <div class="fr page">
  454. <div class="sui-pagination pagination-large">
  455. <ul>
  456. <li class="prev disabled">
  457. <a href="#">«上一页</a>
  458. </li>
  459. <li class="dotted" id="first"><span>...</span></li>
  460. <!--两种处理数字与字符串转换的方式-->
  461. <!--<li th:class="${p+'' == param.page+''} ? 'active' : '' " th:each="p : ${#numbers.sequence(1,resultMap.totalPage)}">-->
  462. <!--<li th:class="${#numbers.formatInteger(p,0) == #numbers.formatInteger(param.page,0)} ? 'active' : '' "-->
  463. <!-- th:each="p : ${#numbers.sequence(1,resultMap.totalPage)}">-->
  464. <!-- <a href="#" th:onclick="findByPage([[${p}]])">[[${p}]]</a>-->
  465. <!--</li>-->
  466. <li class="dotted" id="last"><span>...</span></li>
  467. <li class="next">
  468. <a href="#">下一页»</a>
  469. </li>
  470. </ul>
  471. <div><span>共[[${resultMap.totalPage}]]页&nbsp;</span><span>
  472. 到第
  473. <input type="text" class="page-num">
  474. <button class="page-confirm" onclick="alert(1)">确定</button></span></div>
  475. </div>
  476. </div>
  477. </div>
  478. <!--hotsale-->
  479. <div class="clearfix hot-sale">
  480. <h4 class="title">热卖商品</h4>
  481. <div class="hot-list">
  482. <ul class="yui3-g">
  483. <li class="yui3-u-1-4">
  484. <div class="list-wrap">
  485. <div class="p-img">
  486. <img src="/static/search/img/like_01.png" />
  487. </div>
  488. <div class="attr">
  489. <em>Apple苹果iPhone 6s (A1699)</em>
  490. </div>
  491. <div class="price">
  492. <strong>
  493. <em>¥</em>
  494. <i>4088.00</i>
  495. </strong>
  496. </div>
  497. <div class="commit">
  498. <i class="command">已有700人评价</i>
  499. </div>
  500. </div>
  501. </li>
  502. <li class="yui3-u-1-4">
  503. <div class="list-wrap">
  504. <div class="p-img">
  505. <img src="/static/search/img/like_03.png" />
  506. </div>
  507. <div class="attr">
  508. <em>金属A面,360°翻转,APP下单省300!</em>
  509. </div>
  510. <div class="price">
  511. <strong>
  512. <em>¥</em>
  513. <i>4088.00</i>
  514. </strong>
  515. </div>
  516. <div class="commit">
  517. <i class="command">已有700人评价</i>
  518. </div>
  519. </div>
  520. </li>
  521. <li class="yui3-u-1-4">
  522. <div class="list-wrap">
  523. <div class="p-img">
  524. <img src="/static/search/img/like_04.png" />
  525. </div>
  526. <div class="attr">
  527. <em>256SSD商务大咖,完爆职场,APP下单立减200</em>
  528. </div>
  529. <div class="price">
  530. <strong>
  531. <em>¥</em>
  532. <i>4068.00</i>
  533. </strong>
  534. </div>
  535. <div class="commit">
  536. <i class="command">已有20人评价</i>
  537. </div>
  538. </div>
  539. </li>
  540. <li class="yui3-u-1-4">
  541. <div class="list-wrap">
  542. <div class="p-img">
  543. <img src="/static/search/img/like_02.png" />
  544. </div>
  545. <div class="attr">
  546. <em>Apple苹果iPhone 6s (A1699)</em>
  547. </div>
  548. <div class="price">
  549. <strong>
  550. <em>¥</em>
  551. <i>4088.00</i>
  552. </strong>
  553. </div>
  554. <div class="commit">
  555. <i class="command">已有700人评价</i>
  556. </div>
  557. </div>
  558. </li>
  559. </ul>
  560. </div>
  561. </div>
  562. </div>
  563. </div>
  564. <!-- 底部栏位 -->
  565. <!--页面底部-->
  566. <div class="clearfix footer">
  567. <div class="py-container">
  568. <div class="footlink">
  569. <div class="Mod-service">
  570. <ul class="Mod-Service-list">
  571. <li class="grid-service-item intro intro1">
  572. <i class="serivce-item fl"></i>
  573. <div class="service-text">
  574. <h4>正品保障</h4>
  575. <p>正品保障,提供发票</p>
  576. </div>
  577. </li>
  578. <li class="grid-service-item intro intro2">
  579. <i class="serivce-item fl"></i>
  580. <div class="service-text">
  581. <h4>正品保障</h4>
  582. <p>正品保障,提供发票</p>
  583. </div>
  584. </li>
  585. <li class="grid-service-item intro intro3">
  586. <i class="serivce-item fl"></i>
  587. <div class="service-text">
  588. <h4>正品保障</h4>
  589. <p>正品保障,提供发票</p>
  590. </div>
  591. </li>
  592. <li class="grid-service-item intro intro4">
  593. <i class="serivce-item fl"></i>
  594. <div class="service-text">
  595. <h4>正品保障</h4>
  596. <p>正品保障,提供发票</p>
  597. </div>
  598. </li>
  599. <li class="grid-service-item intro intro5">
  600. <i class="serivce-item fl"></i>
  601. <div class="service-text">
  602. <h4>正品保障</h4>
  603. <p>正品保障,提供发票</p>
  604. </div>
  605. </li>
  606. </ul>
  607. </div>
  608. <div class="clearfix Mod-list">
  609. <div class="yui3-g">
  610. <div class="yui3-u-1-6">
  611. <h4>购物指南</h4>
  612. <ul class="unstyled">
  613. <li>购物流程</li>
  614. <li>会员介绍</li>
  615. <li>生活旅行/团购</li>
  616. <li>常见问题</li>
  617. <li>购物指南</li>
  618. </ul>
  619. </div>
  620. <div class="yui3-u-1-6">
  621. <h4>配送方式</h4>
  622. <ul class="unstyled">
  623. <li>上门自提</li>
  624. <li>211限时达</li>
  625. <li>配送服务查询</li>
  626. <li>配送费收取标准</li>
  627. <li>海外配送</li>
  628. </ul>
  629. </div>
  630. <div class="yui3-u-1-6">
  631. <h4>支付方式</h4>
  632. <ul class="unstyled">
  633. <li>货到付款</li>
  634. <li>在线支付</li>
  635. <li>分期付款</li>
  636. <li>邮局汇款</li>
  637. <li>公司转账</li>
  638. </ul>
  639. </div>
  640. <div class="yui3-u-1-6">
  641. <h4>售后服务</h4>
  642. <ul class="unstyled">
  643. <li>售后政策</li>
  644. <li>价格保护</li>
  645. <li>退款说明</li>
  646. <li>返修/退换货</li>
  647. <li>取消订单</li>
  648. </ul>
  649. </div>
  650. <div class="yui3-u-1-6">
  651. <h4>特色服务</h4>
  652. <ul class="unstyled">
  653. <li>夺宝岛</li>
  654. <li>DIY装机</li>
  655. <li>延保服务</li>
  656. <li>泽易购E卡</li>
  657. <li>泽易购通信</li>
  658. </ul>
  659. </div>
  660. <div class="yui3-u-1-6">
  661. <h4>帮助中心</h4>
  662. <img src="/static/search/img/wx_cz.jpg">
  663. </div>
  664. </div>
  665. </div>
  666. <div class="Mod-copyright">
  667. <ul class="helpLink">
  668. <li>关于我们<span class="space"></span></li>
  669. <li>联系我们<span class="space"></span></li>
  670. <li>关于我们<span class="space"></span></li>
  671. <li>商家入驻<span class="space"></span></li>
  672. <li>营销中心<span class="space"></span></li>
  673. <li>友情链接<span class="space"></span></li>
  674. <li>关于我们<span class="space"></span></li>
  675. <li>营销中心<span class="space"></span></li>
  676. <li>友情链接<span class="space"></span></li>
  677. <li>关于我们</li>
  678. </ul>
  679. <p>地址:深圳市大冲国际</p>
  680. </div>
  681. </div>
  682. </div>
  683. </div>
  684. <!--页面底部END-->
  685. <!--侧栏面板开始-->
  686. <div class="J-global-toolbar">
  687. <div class="toolbar-wrap J-wrap">
  688. <div class="toolbar">
  689. <div class="toolbar-panels J-panel">
  690. <!-- 购物车 -->
  691. <div style="visibility: hidden;" class="J-content toolbar-panel tbar-panel-cart toolbar-animate-out">
  692. <h3 class="tbar-panel-header J-panel-header">
  693. <a href="" class="title"><i></i><em class="title">购物车</em></a>
  694. <span class="close-panel J-close" onclick="cartPanelView.tbar_panel_close('cart');" ></span>
  695. </h3>
  696. <div class="tbar-panel-main">
  697. <div class="tbar-panel-content J-panel-content">
  698. <div id="J-cart-tips" class="tbar-tipbox hide">
  699. <div class="tip-inner">
  700. <span class="tip-text">还没有登录,登录后商品将被保存</span>
  701. <a href="#none" class="tip-btn J-login">登录</a>
  702. </div>
  703. </div>
  704. <div id="J-cart-render">
  705. <!-- 列表 -->
  706. <div id="cart-list" class="tbar-cart-list">
  707. </div>
  708. </div>
  709. </div>
  710. </div>
  711. <!-- 小计 -->
  712. <div id="cart-footer" class="tbar-panel-footer J-panel-footer">
  713. <div class="tbar-checkout">
  714. <div class="jtc-number"> <strong class="J-count" id="cart-number">0</strong>件商品 </div>
  715. <div class="jtc-sum"> 共计:<strong class="J-total" id="cart-sum">¥0</strong> </div>
  716. <a class="jtc-btn J-btn" href="/static/search/#none" target="_blank">去购物车结算</a>
  717. </div>
  718. </div>
  719. </div>
  720. <!-- 我的关注 -->
  721. <div style="visibility: hidden;" data-name="follow" class="J-content toolbar-panel tbar-panel-follow">
  722. <h3 class="tbar-panel-header J-panel-header">
  723. <a href="#" target="_blank" class="title"> <i></i> <em class="title">我的关注</em> </a>
  724. <span class="close-panel J-close" onclick="cartPanelView.tbar_panel_close('follow');"></span>
  725. </h3>
  726. <div class="tbar-panel-main">
  727. <div class="tbar-panel-content J-panel-content">
  728. <div class="tbar-tipbox2">
  729. <div class="tip-inner"> <i class="i-loading"></i> </div>
  730. </div>
  731. </div>
  732. </div>
  733. <div class="tbar-panel-footer J-panel-footer"></div>
  734. </div>
  735. <!-- 我的足迹 -->
  736. <div style="visibility: hidden;" class="J-content toolbar-panel tbar-panel-history toolbar-animate-in">
  737. <h3 class="tbar-panel-header J-panel-header">
  738. <a href="#" target="_blank" class="title"> <i></i> <em class="title">我的足迹</em> </a>
  739. <span class="close-panel J-close" onclick="cartPanelView.tbar_panel_close('history');"></span>
  740. </h3>
  741. <div class="tbar-panel-main">
  742. <div class="tbar-panel-content J-panel-content">
  743. <div class="jt-history-wrap">
  744. <ul>
  745. <!--<li class="jth-item">
  746. <a href="/static/search/#" class="img-wrap"> <img src="/static/search/.portal/img/like_03.png" height="100" width="100" /> </a>
  747. <a class="add-cart-button" href="/static/search/#" target="_blank">加入购物车</a>
  748. <a href="/static/search/#" target="_blank" class="price">¥498.00</a>
  749. </li>
  750. <li class="jth-item">
  751. <a href="/static/search/#" class="img-wrap"> <img src="/static/search/portal/img/like_02.png" height="100" width="100" /></a>
  752. <a class="add-cart-button" href="/static/search/#" target="_blank">加入购物车</a>
  753. <a href="/static/search/#" target="_blank" class="price">¥498.00</a>
  754. </li>-->
  755. </ul>
  756. <a href="/static/search/#" class="history-bottom-more" target="_blank">查看更多足迹商品 &gt;&gt;</a>
  757. </div>
  758. </div>
  759. </div>
  760. <div class="tbar-panel-footer J-panel-footer"></div>
  761. </div>
  762. </div>
  763. <div class="toolbar-header"></div>
  764. <!-- 侧栏按钮 -->
  765. <div class="toolbar-tabs J-tab">
  766. <div onclick="cartPanelView.tabItemClick('cart')" class="toolbar-tab tbar-tab-cart" data="购物车" tag="cart">
  767. <i class="tab-ico"></i>
  768. <em class="tab-text"></em>
  769. <span class="tab-sub J-count " id="tab-sub-cart-count">0</span>
  770. </div>
  771. <div onclick="cartPanelView.tabItemClick('follow')" class="toolbar-tab tbar-tab-follow" data="我的关注" tag="follow">
  772. <i class="tab-ico"></i>
  773. <em class="tab-text"></em>
  774. <span class="tab-sub J-count hide">0</span>
  775. </div>
  776. <div onclick="cartPanelView.tabItemClick('history')" class="toolbar-tab tbar-tab-history" data="我的足迹" tag="history">
  777. <i class="tab-ico"></i>
  778. <em class="tab-text"></em>
  779. <span class="tab-sub J-count hide">0</span>
  780. </div>
  781. </div>
  782. <div class="toolbar-footer">
  783. <div class="toolbar-tab tbar-tab-top">
  784. <a href="/static/search/#"> <i class="tab-ico "></i> <em class="footer-tab-text">顶部</em> </a>
  785. </div>
  786. <div class="toolbar-tab tbar-tab-feedback">
  787. <a href="/static/search/#" target="_blank"> <i class="tab-ico"></i> <em class="footer-tab-text ">反馈</em> </a>
  788. </div>
  789. </div>
  790. <div class="toolbar-mini"></div>
  791. </div>
  792. <div id="J-toolbar-load-hook"></div>
  793. </div>
  794. </div>
  795. <!--购物车单元格 模板-->
  796. <script type="text/template" id="tbar-cart-item-template">
  797. <div class="tbar-cart-item">
  798. <div class="jtc-item-promo">
  799. <em class="promo-tag promo-mz">满赠<i class="arrow"></i></em>
  800. <div class="promo-text">已购满600元,您可领赠品</div>
  801. </div>
  802. <div class="jtc-item-goods">
  803. <span class="p-img"><a href="/static/search/#" target="_blank"><img src="/static/search/{2}" alt="{1}" height="50" width="50" /></a></span>
  804. <div class="p-name">
  805. <a href="/static/search/#">{1}</a>
  806. </div>
  807. <div class="p-price"><strong>¥{3}</strong>×{4} </div>
  808. <a href="/static/search/#none" class="p-del J-del">删除</a>
  809. </div>
  810. </div>
  811. </script>
  812. <!--侧栏面板结束-->
  813. <script type="text/javascript" src="/static/search/js/plugins/jquery/jquery.min.js"></script>
  814. <!-- -->
  815. <script type="text/javascript">
  816. $(function() {
  817. $("#service").hover(function() {
  818. $(".service").show();
  819. }, function() {
  820. $(".service").hide();
  821. });
  822. $("#shopcar").hover(function() {
  823. $("#shopcarlist").show();
  824. }, function() {
  825. $("#shopcarlist").hide();
  826. });
  827. })
  828. </script>
  829. <script type="text/javascript" src="/static/search/js/model/cartModel.js"></script>
  830. <script type="text/javascript" src="/static/search/js/czFunction.js"></script>
  831. <script type="text/javascript" src="/static/search/js/plugins/jquery.easing/jquery.easing.min.js"></script>
  832. <script type="text/javascript" src="/static/search/js/plugins/sui/sui.min.js"></script>
  833. <script type="text/javascript" src="/static/search/js/widget/cartPanelView.js"></script>
  834. </body>
  835. </html>

1.2 后台:

1.2.1 ItemVo实体类:

  1. @Data
  2. @AllArgsConstructor
  3. @NoArgsConstructor
  4. public class ItemVo implements Serializable {
  5. //1. 查询关键字对象
  6. private String keywords;
  7. //2. 商品分类
  8. private String category;
  9. //3. 品牌查询
  10. private String brand;
  11. //4. 规格查询(类似:[网络:4G,机身内存:128G])
  12. private List<String> spec;
  13. //5. 价格区间(price:500_1000)
  14. private String price;
  15. //6. 排序(类似:asc:price)
  16. private String sort;
  17. //7. 当前页
  18. private int page = 1;
  19. //8. 每页大小
  20. private int pageSize = 10;
  21. }

1.2.2 ItemSearchServiceImpl服务层:

  1. ...
  2. //3.1 得到当前页
  3. int page = params.getPage();
  4. //3.2 得到每页大小
  5. int pageSize = params.getPageSize();
  6. NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder()
  7. .withPageable(PageRequest.of(page - 1,pageSize));
  8. ...
  9. //21. 存放高亮数据到大集合
  10. resultMap.put("rows",highlights); //当前分页记录集合
  11. resultMap.put("categoryList",categoryList); //分类
  12. resultMap.put("total",total); //总记录数
  13. resultMap.put("totalPage",totalPage); //总页数

二、与首页对接 :

2.1 在portal-web这个模块中的resources/index.html文件中添加:

  1. <!-- JS部分: -->
  2. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  3. <script>
  4. function search(){
  5. //1. 得到搜索框中的内容
  6. let keywords = $("#keywords").val();
  7. //2. 跳转到搜索页面
  8. location.href = "http://search.zeyigou.com?keywords=" + keywords;
  9. }
  10. </script>
  11. <!-- HTML部分: -->
  12. <form action="" class="sui-form form-inline">
  13. <!--searchAutoComplete-->
  14. <div class="input-append">
  15. <input type="text" id="keywords" class="input-error input-xxlarge" />
  16. <button class="sui-btn btn-xlarge btn-danger" type="button" onclick="search()">搜索</button>
  17. </div>
  18. </form>

2.2 运行效果如下:
image.png

三、商品审核通过后,同步索引库:

3.1 在zyg-manager-web工程的goodsController中审核方法修改如下:

  1. /**
  2. * 功能: 批量审核数据
  3. * 参数:
  4. * 返回值: com.zelin.utils.R
  5. * 时间: 2021/7/30 16:11
  6. */
  7. @RequestMapping("/updateStatus")
  8. public R updateStatus(Long[] ids,String status){
  9. //1. 审核商品
  10. goodsService.updateStatus(ids,status);
  11. //2. 根据商品id查询sku列表
  12. List<ItemEntity> entities = itemService.findItemsbyGoodsId(ids);
  13. //3. 查询出tb_item表的数据并同时更新到索引库中(增量更新)
  14. if(status.equals("1") && entities.size() > 0) {
  15. searchService.updateToIndex(entities);
  16. }
  17. return R.ok();
  18. }

3.2 在zyg-sellerGoods-Service工程添加findItemsbyGoodsId()

  1. @Override
  2. public List<ItemEntity> findItemsbyGoodsId(Long... ids) {
  3. return this.baseMapper.selectList(new QueryWrapper<ItemEntity>().in("goods_id",ids));
  4. }

3.3 在zyg-search-Service工程定义导入到索引库方法:

  1. /**
  2. * 功能: 将所有的商品添加到索引库中(增量更新)
  3. * 参数:
  4. * 返回值: void
  5. * 时间: 2021/8/5 16:54
  6. */
  7. @Override
  8. public void updateToIndex(List<ItemEntity> entities) {
  9. restTemplate.save(entities);
  10. }

3.4 最后在kibana中查询结果:

image.png