当前位置:网站首页>秒殺系統3-商品列錶和商品詳情
秒殺系統3-商品列錶和商品詳情
2022-07-03 15:20:00 【ジ你是我永遠のbugグ】
1、首先在數據庫添加數據
INSERT INTO `t_goods` VALUES (1, 'Iphone 12 64G', 'Iphone 12 64G', '/img/iphone12.png', 'Iphone 12 64G', 5299.00, 100);
INSERT INTO `t_goods` VALUES (2, 'Iphone12Pro128G', 'Iphone12Pro128G', '/img/iphone12pro.png', 'Iphone12Pro128G', 6299.00, 100);
INSERT INTO `t_seckill_goods` VALUES (1, 1, 4299.00, 10, '2022-06-15 00:00:00', '2022-07-15 00:00:00');
INSERT INTO `t_seckill_goods` VALUES (2, 2, 5299.00, 10, '2022-06-15 00:00:00', '2022-07-15 00:00:00');
2、根據 Mybatis-plus 逆向工程將數據庫錶生成相應文件
3、在接口中獲取 商品列錶
package com.example.seckill.controller;
import com.example.seckill.common.RespBean;
import com.example.seckill.controller.parm.LoginRequestParam;
import com.example.seckill.pojo.User;
import com.example.seckill.service.IGoodsService;
import com.example.seckill.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@RequestMapping("/goods")
@Controller
@Slf4j
public class GoodsController {
@Autowired
IGoodsService goodsService;
@Autowired
IUserService userService;
/** * 跳轉商品頁 * @param * @param model * @param * @return */
@RequestMapping("/toList")
public String toList(Model model,User user){
// 將用戶信息 傳到前端頁面
model.addAttribute("user",user);
model.addAttribute("goodsList",goodsService.findGoodsList());
return "goodsList";
}
}
package com.example.seckill.service.impl;
import com.example.seckill.controller.outPutParm.GoodsListOutPut;
import com.example.seckill.pojo.Goods;
import com.example.seckill.mapper.GoodsMapper;
import com.example.seckill.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/** * <p> * 商品錶 服務實現類 * </p> * * @author jobob * @since 2022-06-14 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {
@Autowired(required = false)
GoodsMapper goodsMapper;
/** * 獲取商品列錶 * @return */
@Override
public List<GoodsListOutPut> findGoodsList() {
List<GoodsListOutPut> goodsList= goodsMapper.findGoodsList();
return goodsList;
}
}
<select id="findGoodsList" resultType="com.example.seckill.controller.outPutParm.GoodsListOutPut">
SELECT g.id,
g.goods_name,
g.goods_title,
g.goods_img,
g.goods_price,
g.goods_stock,
sg.seckill_price,
sg.stock_count,
sg.start_date,
sg.end_date
FROM t_goods g
LEFT JOIN t_seckill_goods sg on g.id = sg.goods_id
</select>
以及前端商品列錶頁面
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>商品列錶</title>
<!-- jquery -->
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<!-- bootstrap -->
<link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}"/>
<script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<!-- layer -->
<script type="text/javascript" th:src="@{/layer/layer.js}"></script>
<!-- common.js -->
<script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading">秒殺商品列錶</div>
<table class="table" id="goodslist">
<tr>
<td>商品名稱</td>
<td>商品圖片</td>
<td>商品原價</td>
<td>秒殺價</td>
<td>庫存數量</td>
<td>詳情</td>
</tr>
<tr th:each="goods,goodsStat : ${goodsList}">
<td th:text="${goods.goodsName}"></td>
<td><img th:src="@{${goods.goodsImg}}" width="100" height="100"/></td>
<td th:text="${goods.goodsPrice}"></td>
<td th:text="${goods.seckillPrice}"></td>
<td th:text="${goods.stockCount}"></td>
<td><a th:href="'/goodsDetail.html?goodsId='+${goods.id}">詳情</a></td>
</tr>
</table>
</div>
</body>
</html>
運行:
边栏推荐
- Summary of JVM knowledge points
- 阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
- Halcon与Winform学习第一节
- 第04章_逻辑架构
- socket.io搭建分布式Web推送服务器
- 百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
- Redis single thread problem forced sorting layman literacy
- [set theory] inclusion exclusion principle (complex example)
- Popular understanding of linear regression (I)
- Nppexec get process return code
猜你喜欢

Popular understanding of ovo and ovr

Jvm-08-garbage collector

What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry

求字符串函数和长度不受限制的字符串函数的详解

Functional modules and application scenarios covered by the productization of user portraits

整形和浮点型是如何在内存中的存储

GCC cannot find the library file after specifying the link library path

解决pushgateway数据多次推送会覆盖的问题

C语言刷题~Leetcode与牛客网简单题

Chapter 04_ Logical architecture
随机推荐
Matlab r2011b neural network toolbox precautions
What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
Kubernetes帶你從頭到尾捋一遍
【Transformer】入门篇-哈佛Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文The Annotated Transformer
C语言刷题~Leetcode与牛客网简单题
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
Jvm-06-execution engine
Redis single thread problem forced sorting layman literacy
Redis主从、哨兵、集群模式介绍
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
运维体系的构建
Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock
Visual upper system design and development (Halcon WinForm) -4 Communication management
Jvm-05-object, direct memory, string constant pool
Jvm-09 byte code introduction
Influxdb2 sources add data sources
北京共有产权房出租新规实施的租赁案例
Enable multi-threaded download of chrome and edge browsers
Digital image processing -- popular understanding of corrosion and expansion
Jvm-08-garbage collector