1. 创建数据表

1.1在store数据库中创建t_product数据表

CREATE TABLE t_product (id int(20) NOT NULL COMMENT '商品id',category_id int(20) DEFAULT NULL COMMENT '分类id',item_type varchar(100) DEFAULT NULL COMMENT '商品系列',title varchar(100) DEFAULT NULL COMMENT '商品标题',sell_point varchar(150) DEFAULT NULL COMMENT '商品卖点',price bigint(20) DEFAULT NULL COMMENT '商品单价',num int(10) DEFAULT NULL COMMENT '库存数量',image varchar(500) DEFAULT NULL COMMENT '图片路径',`status` int(1) DEFAULT '1' COMMENT '商品状态  1:上架   2:下架   3:删除',priority int(10) DEFAULT NULL COMMENT '显示优先级',created_time datetime DEFAULT NULL COMMENT '创建时间',modified_time datetime DEFAULT NULL COMMENT '最后修改时间',created_user varchar(50) DEFAULT NULL COMMENT '创建人',modified_user varchar(50) DEFAULT NULL COMMENT '最后修改人',PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

1.2 插入数据

LOCK TABLES t_product WRITE;
INSERT INTO t_product VALUES (10000001,238,'牛皮纸记事本','广博(GuangBo)10本装40张A5牛皮纸记事本子日记本办公软抄本GBR0731','经典回顾!超值特惠!',23,99999,'/images/portal/00GuangBo1040A5GBR0731/',1,62,'2017-10-25 15:08:55','2017-10-25 15:08:55','admin','admin'),等等等等;
UNLOCK TABLES;

2.创建实体类

/** 商品数据的实体类 */
public class Product extends BaseEntity {private Integer id;private Integer categoryId;private String itemType;private String title;private String sellPoint;private Long price;private Integer num;private String image;private Integer status;private Integer priority;/*** get,set* equals和hashCode* toString*/
}

3.商品热销排行-持久层

3.1规划SQL语句

select * from t_product ORDER BY priority desc limit 0,4

3.2 编写接口和抽象方法

public interface ProductMapper {/*** 查询排在前四的热销商品* @return list*/List<Product> findHotList();
}

3.3 编写映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--命名就是接口的全类名-->
<mapper namespace="com.sdjzu.store.mapper.ProductMapper"><resultMap id="ProductEntiyMap" type="com.sdjzu.store.entity.Product"><id column="id" property="id"/><result column="category_id" property="categoryId"/><result column="item_type" property="itemType"/><result column="sell_point" property="sellPoint"/><result column="created_user" property="createdUser"/><result column="created_time" property="createdTime"/><result column="modified_user" property="modifiedUser"/><result column="modified_time" property="modifiedTime"/></resultMap><select id="findHotList" resultMap="ProductEntiyMap">select * from t_product ORDER BY priority desc limit 0,4</select>
</mapper>

4. 商品热销排行-业务层

4.1编写接口和抽象方法

/*热销商品排行*/
public interface IProductService {/*** 查询排列前四的商品* @return*/List<Product> findHotProduct();
}

4.2编写实现类和抽象方法

@Service
public class ProductServiceImpl implements IProductService {@Autowiredprivate ProductMapper productMapper;@Overridepublic List<Product> findHotProduct() {List<Product> list = productMapper.findHotList();for (Product product : list) {product.setPriority(null);product.setCreatedUser(null);product.setCreatedTime(null);product.setModifiedUser(null);product.setModifiedTime(null);}return list;}
}

5.热销商品排行-控制层

5.1设计请求

  1. /products/hot_list
  2. GET
  3. 不需要请求参数
  4. JsonResult<List>

5.2处理请求


@RequestMapping("product")
@RestController
public class ProductController extends BaseController{@Autowiredprivate IProductService iProductService;@RequestMapping("hotProList")public JsonResult<List<Product>> findHotProduct(){List<Product> data = iProductService.findHotProduct();return new JsonResult<List<Product>>(ok, data);}}

6.热销商品排行-前端

<script type="text/javascript">$(document).ready(function() {showHotList();
});function showHotList() {$("#hot-list").empty();$.ajax({url: "/product/hotProList",type: "GET",dataType: "JSON",success: function(json) {var list = json.data;for (var i = 0; i < list.length; i++) {console.log(list[i].title);//调试用var html = '<div class="col-md-12">'+ '<div class="col-md-7 text-row-2"><a href="product.html?id=#{id}">#{title}</a></div>'+ '<div class="col-md-2">¥#{price}</div>'+ '<div class="col-md-3"><img src="..#{image}collect.png" class="img-responsive" /></div>'+ '</div>';html = html.replace(/#{id}/g, list[i].id);html = html.replace(/#{title}/g, list[i].title);html = html.replace(/#{price}/g, list[i].price);html = html.replace(/#{image}/g, list[i].image);$("#hot-list").append(html);}}});
}
</script>

【store商城项目09】商品热销排行相关推荐

  1. 商品热销排行【项目 商城】

    商品热销排行[项目 商城] 商品热销排行 1.商品--创建数据表 2.商品--创建实体类 3.商品热销排行--持久层 3.1 规划查询的SQL语句 3.2 接口与抽象方法 3.3 配置SQL映射 4. ...

  2. 美多商城项目:商品数据库表设计、准备商品数据、首页广告、商品列表页

    一.商品数据库表设计 1.1 SPU和SKU 在电商中对于商品,有两个重要的概念:SPU和SKU 1. SPU介绍 SPU = Standard Product Unit (标准产品单位) SPU是商 ...

  3. 谷粒商城项目8——商品上架 上架商品sku保存到es nginx配置

    文章目录 一.商城业务 1.商品上架 1.1 ES 的存储结构分析 1.2 PUT product 1.3 一些细节 2.商品上架-构造基本数据 3.商品上架-业务代码: 4.商品上架-search模 ...

  4. (十)搭建springboot商城--商品热销排行

    1创建数据库 2.创建实体类Product public class Product extends BaseEntity implements Serializable {private Integ ...

  5. Flutter-防京东商城项目-创建商品数据模型 、请求Api接口渲染热门商品 推荐商品 获取数据然后模型赋值-06

    一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹.靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希 ...

  6. 商城项目14_商品新增vo抽取、修改vo、新增逻辑、代码的具体落地、SPU检测、SKU检测、流程图

    文章目录 ①. 商品新增vo抽取 ②. 修改新增的vo ③. 新增商品的逻辑 ④. 保存商品核心代码 ⑤. 商品管理 - SPU检测 ⑥. 商品管理 - SKU检测 ⑦. 商品保持流程图 - 超级重要 ...

  7. Django项目实战——14—(列表页热销排行、商品搜索、Haystack建立数据索引、渲染商品搜索结果、商品详情页)

    1.列表页热销排行 根据路径参数category_id查询出该类型商品销量前二的商品. 使用Ajax实现局部刷新的效果. 查询列表页热销排行数据 请求方式 请求参数:路径参数 响应结果:JSON {& ...

  8. springboot的商品设计热销排行实现

    一.SpringBoot是什么? SpringBoot是spring家族中微型框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. Spring Boot可以轻松创建独立的,生产级的基 ...

  9. 使用SpringBoot编写电脑商城项目笔记(每一步都详细记录,前后端数据交互使用html+ajax+json)

    项目环境 JDK1.8 Maven3.8.3 Tomcat9.0.54 Mysql8.0 技术栈:springboot+mybatis+mysql+html+javascript+css+json+j ...

最新文章

  1. spring-boot入门之二——验证、AOP日志、异常处理
  2. 激光点云格式转换 bin 相互 pcd转换
  3. python2 dict 乱序_为什么我的python dict变得无序?
  4. 一个弱智问题, Ubuntu 中gedit 菜单栏在哪里?
  5. Django之web框架的本质
  6. 一个黑色全屏的计时器_我入手了一个1000多的智能手环,值吗?|Fitbit Charge 4测评...
  7. c语言正则表达式库,c语言正则表达式库--PCRE
  8. python身份证号码共18位_涨姿势:用Python完成15位18位身份证的互转
  9. 快速清理C盘的四个方法
  10. 金蝶KIS标准迷你版专业版 K3 引出报表提示保存文件失败,原因:Automation错误
  11. 一封学生来信:突破大学的迷茫
  12. FFMPEG,vlc介绍和视频直播,obs(zz)
  13. Android简单的编写一个txt阅读器(没有处理字符编码),适用于新手学习
  14. 【安全硬件】Chap.6 IC和半导体产业的全球化;芯片生产猜疑链与SoC设计流程;可能会存在的安全威胁: 硬件木马、IP盗版、逆向工程、侧信道攻击、伪造
  15. 触及办事质量黑白、是否跟商家承诺的一致
  16. linux的web服务
  17. 拖拽即可创建HTML5网站的建站平台
  18. print list Reversely
  19. unity 2d角色移动卡住的原因
  20. Paper Reading 《SimCSE》

热门文章

  1. 使用 public 文件夹
  2. 使用JS分页 span beta 3.0 完成封装的分页
  3. AD域:添加辅域控制器(辅域服务器)
  4. no such window: target window already closed
  5. C语言-区域相邻题目
  6. TCP、UDP报文格式
  7. 钱诚9.16黄金独家指导解套,美原油行情价格趋势分析
  8. python字典嵌套列表_Python 字典 列表 嵌套 复杂排序大全
  9. 我省首个SGS绿色洗涤系统落户敬业钢城洗涤厂
  10. 文字工作者大敌?从征人文案到一首好诗,Notion AI都能「写」出来