秒杀项目
秒杀项目基本环境搭建
商品展示模块
请求执行秒杀模块
秒杀流程总结

商品详情页展示模块

在15-seckill-web中的GoodsController中添加跳转详情页的方法,并将商品信息传递给前端页面

@GetMapping("/seckill/goods/{id}")
public String item(@PathVariable("id") Integer id,Model model){
    //根据商品id,从Redis中获取商品Json字符串
    String goodsJSON = redisTemplate.opsForValue().get(Constants.REDIS_GOODS + id);
    Goods goods = JSONObject.parseObject(goodsJSON,Goods.class);
    model.addAttribute("goods",goods);
    //因为在详情页需要显示秒杀按钮,所有我们将服务器当前时间传递给详情页
    model.addAttribute("currentTime",System.currentTimeMillis());
    return "item";
}

在15-seckill-web中templates下定义商品详情页item.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>秒杀商品详情页</title>
</head>
<body th:inline="text" style="margin: 50px;">
    <!--左侧div-->
    <div style="float: left">
        <a th:href="@{'/seckill/goods/' + ${goods.getId()}}" target="_blank">
            <img th:src="@{${goods.imageurl}}"><br>
        </a>
    </div>
    <!--右侧div-->
    <div style="float: left">
        <p>
            <a th:href="@{'/seckill/goods/' + ${goods.getId()}}" target="_blank">
                [[${goods.name}]] [[${goods.namedesc}]]<br>
            </a>
        </p>
        <p>
            <span style="color: red;font-size:22px;font-weight: bold;">[[${goods.price}]]</span>
        </p>
        <p>
            剩余:[[${goods.store}]]件
        </p>
    </div>
</body>
</html>

 

全部教程