3-2 商品列表页

GoodsController类中定义如下:

package com.mydre.miaosha.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.*;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.mydre.miaosha.domain.MiaoshaUser;
import com.mydre.miaosha.service.GoodsService;
import com.mydre.miaosha.service.MiaoshaUserService;
import com.mydre.miaosha.vo.GoodsVo;
@Controller
@RequestMapping("/goods")
public class GoodsController {
@Autowired
MiaoshaUserService miaoshaUserService;
@Autowired
GoodsService goodsService;
@RequestMapping("/to_list")
    public String list(Model model, MiaoshaUser user) {
List<GoodsVo> goodsList =  goodsService.listGoodsVo();
model.addAttribute("goodsList", goodsList);
model.addAttribute("user", user);
        return "goods_list";
}

2、定义goods_list.html

<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org"><!-- 引入thymeleaf 的 命名空间(th) -->
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
<title>商品列表</title>
<!-- jquery -->
<!-- 这里 / 代表 的是static文件夹,这是thymeleaf引入静态文件的方式。 -->
<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}"></link>
<script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<!-- jquery-validation -->
<script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
<script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.js}"></script>
<!-- layer -->
<script type="text/javascript" th:src="@{/layer/layer.js}"></script>
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading">秒杀商品列表</div>
<table id="goodslist" class="table">
<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.miaoshaPrice}"></td>
<td th:text="${goods.stockCount}"></td>
<td> <a th:href="'/goods/to_detail/' + ${goods.id}">详情</a></td>
</tr>
</table>
</div>
</body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值