【前端】【thymeleaf】thymeleaf初始化的表格循环

thymeleaf初始化的表格循环

后端controller层

@RequestMapping("/comment_manage")
public String comment_managePage(Model model) {
    List<Comment> l = commentService.selectAllList();
    model.addAttribute("commentList", l);
    return "comment_manage";
}

Thymeleaf

我们也可以使用th:each="s,status:${students}"方式遍历,就可以把状态放在status里面了,
同时还可以用th:class="${stauts.even}?'even':'odd'"来判断奇偶。
status里面包含的信息大致如下:
属性说明index从0开始的索引值
count从1开始的索引值
size集合内元素的总量
current当前的迭代对象
even/odd boolean类型的,用来判断是偶数个还是奇数个
firstboolean类型,判断是否为第一个
lastboolean类型,判断是否为最后一个

img、onclick

<table class="table table-bordered">
    <thead>
        <tr>
            <th>#</th>
            <th>commentId</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="info,infoStat:${commentList}">
            <td th:text="${infoStat.index}"></td>
            <td th:text="${info.commentId}"></td>
            <td>
                <div class="box-body no-padding">
                    <ul class="users-list clearfix">
                        <img src="images/undefine.jpg"
                            th:src="@{'images/'+${info.imagePath}}"
                            style="width:40px; height:40px" alt="User Image">
                    </ul>
                </div>
            </td>
            <td>
                <div class="btn-group">
                    <button th:onclick="modifyComment([[${info.commentId}]]);"
                        type="button" class="btn btn-info" data-toggle="modal"
                        data-target="#modal-default">修改</button>
                    <button th:onclick="deleteComment([[${info.commentId}]]);"
                        type="button" class="btn btn-success">删除</button>
                </div>
            </td>
        </tr>
    </tbody>
</table>

switch

<tr th:each="info,infoStat:${purchase_done_list}">
    <td th:text="${infoStat.index}"></td>
    <td th:text="${info.orderId}"></td>
    <td th:text="${info.sellerId}"></td>

    <td th:text="${info.goodId}"></td>
    <td th:text="${info.purchaserId}"></td>
    <td th:text="${info.addressId}"></td>
    <!-- <td th:text="${info.shippingMethod}"></td> -->
    <td th:switch="${info.shippingMethod}">
        <p th:case="1">顺丰</p>
        <p th:case="2">圆通</p>
        <p th:case="3">中通</p>
        <p th:case="4">申通</p>
        <p th:case="*">其他</p>
    </td>
    <!-- <td th:text="${info.pickupMethod}"></td> -->
    <td th:switch="${info.shippingMethod}">
        <p th:case="1">网点自提</p>
        <p th:case="2">送货上门</p>
        <p th:case="*">其他</p>
    </td>
    <!-- <td th:text="${info.usePoint}"></td> -->
    <td th:text="${info.usePoint == true}?'':''"></td>
    <!-- <td th:text="${info.orderState}"></td> -->
    <td th:switch="${info.orderState}">
        <p th:case="0">未发货</p>
        <p th:case="1">物流中</p>
        <p th:case="2">确认收货</p>
        <p th:case="3">退货</p>
        <p th:case="4">换货</p>
        <p th:case="5">维修</p>
        <p th:case="*">其他</p>
    </td>
    <td th:text="${info.gainPoint}"></td>
    <td th:text="${info.createDate}"></td>
    <td>
        <div class="btn-group">
            <span href="#" class="btn-success new-tag">详情</span>
            <span th:onclick="deleteOrder([[${info.orderId}]]);"
                type="button"
                class="btn-danger new-tag">删除</span>
        </div>
    </td>
</tr>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值