当前位置:网站首页>秒杀系统3-商品列表和商品详情
秒杀系统3-商品列表和商品详情
2022-07-03 15:18: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>
运行:
边栏推荐
- Leetcode the smallest number of the rotation array of the offer of the sword (11)
- redis缓存穿透,缓存击穿,缓存雪崩解决方案
- Use of Tex editor
- Kubernetes advanced training camp pod Foundation
- Visual upper system design and development (Halcon WinForm) -1 Process node design
- mysql innodb 存储引擎的特性—行锁剖析
- [attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
- GCC cannot find the library file after specifying the link library path
- 北京共有产权房出租新规实施的租赁案例
- Stress test WebService with JMeter
猜你喜欢

Matplotlib drawing label cannot display Chinese problems

第04章_逻辑架构

Summary of JVM knowledge points

Construction of operation and maintenance system

需要知道的字符串函数
![[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller](/img/a4/2156b61fbf50db65fdf59c8f5538f8.png)
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller

Finally, someone explained the financial risk management clearly
![[set theory] inclusion exclusion principle (complex example)](/img/9a/db5a75e27516378c31531773a8a221.jpg)
[set theory] inclusion exclusion principle (complex example)

【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器

北京共有产权房出租新规实施的租赁案例
随机推荐
Halcon与Winform学习第一节
秒杀系统2-Redis解决分布式Session问题
视觉上位系统设计开发(halcon-winform)
Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Analysis of development mode process based on SVN branch
SQL server installation location cannot be changed
Halcon and WinForm study section 1
Redis lock Optimization Practice issued by gaobingfa
视觉上位系统设计开发(halcon-winform)-2.全局变量设计
What is machine reading comprehension? What are the applications? Finally someone made it clear
Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
需要知道的字符串函数
【可能是全中文网最全】pushgateway入门笔记
视觉上位系统设计开发(halcon-winform)-5.相机
The method of parameter estimation of user-defined function in MATLAB
socket.io搭建分布式Web推送服务器
Stress test WebService with JMeter
Kubernetes 进阶训练营 Pod基础
Puppet automatic operation and maintenance troubleshooting cases