SpringBoot+Thymeleaf整合,th:each遍历图片横向或者纵向超过屏幕解决问题,让遍历每次展示固定图片或者文本

关键代码:

 <td class="col-xs-6 col-md-2" th:each="com:${coms}" th:if="${comStat.index lt 5} ">
 <td class="col-xs-6 col-md-2" th:each="com:${coms}" th:if="${ comStat.index ge 5 &&  comStat.index le 10} ">

遍历两次,第一次0-5,第二次5-10;如果不这么做 遍历一次性10个只能一列或者一行展示

效果

关于th:if判断的一些语法

less than :小于< lt

less equal  :小于等于<= le

great than : 大于> gt

great  equal :大于等于>= ge

还可以做 and or操作 具体见上面我的代码!

整体代码:

前端部分:

<tr>
                    <td class="col-xs-6 col-md-2" th:each="com:${coms}" th:if="${comStat.index lt 5} ">
                        <a th:href="@{/membershow(name=${com.getName()},brand=${com.getBrand()},type=${com.getType()},adapt=${com.getAdapt()},price=${com.getPrice()})}"  class="thumbnail">
                        <img class="layui-nav-item" th:src="@{|/computerImg/${com.name}1.jpg|}" alt="" style="height:230px; width: 280px" >
                                                                                                    <!--style="height: 200px; width: 100%; display: block;"-->
                            <div class="caption" style="text-align: left;">
                            </a>
                            <div>
                                <span th:text="|${com.brand}-${com.name}|"></span>
                            </div>
                            <div>
                                <span style="color: #eb7350;">&yen;
                                    <span th:text="${com.price}"></span>
                                </span>
                            </div>
                            <a th:href="'javascript:focus('+ ${com.name} +')'" class="btn btn-primary"
                               style="font-size: 10px;">加入购物车</a>
                            <!--<td>                                                                                                                                                                                                                                                  &lt;!&ndash;900,500&ndash;&gt;
                            <u  th:url="|@{/Order}|" th:onclick="member_show('电脑详细查看',this.getAttribute('url'),'10001','850','350')">
                            </u>
                            </td>-->
                            <a th:url="|@{/Order(id=${com.id},name=${com.name},price=${com.price},brand=${com.brand})}|"
                               class="btn btn-primary" th:onclick="member_show('请填写你的订单',this.getAttribute('url'),'10001','680','460')"
                                    style="font-size: 10px;">购买</a>
                    </td>
                </tr>
<tr>
                    <td class="col-xs-6 col-md-2" th:each="com:${coms}" th:if="${ comStat.index ge 5 &&  comStat.index le 10} ">
                        <a th:href="@{/membershow(name=${com.getName()},brand=${com.getBrand()},type=${com.getType()},adapt=${com.getAdapt()},price=${com.getPrice()})}"  class="thumbnail">
                        <img class="layui-nav-item" th:src="@{|/computerImg/${com.name}1.jpg|}" alt="" style="height:230px; width: 280px" >
                                                                                                    <!--style="height: 200px; width: 100%; display: block;"-->
                            <div class="caption" style="text-align: left;">
                            </a>
                            <div>
                                <span th:text="|${com.brand}-${com.name}|"></span>
                            </div>
                            <div>
                                <span style="color: #eb7350;">&yen;
                                    <span th:text="${com.price}"></span>
                                </span>
                            </div>
                            <a th:href="'javascript:focus('+ ${com.name} +')'" class="btn btn-primary"
                               style="font-size: 10px;">加入购物车</a>
                        <a th:url="|@{/Order(id=${com.id},name=${com.name},price=${com.price},brand=${com.brand})}|"
                           class="btn btn-primary" th:onclick="member_show('请填写你的订单',this.getAttribute('url'),'10001','500','350')"
                           style="font-size: 10px;">购买</a>
                    </td>
                </tr>

后端:

 @RequestMapping("/ComputerIndex")
    public String ComIndex(Model model){
        Collection<Computer> computers = computerDao.getAll();
        model.addAttribute("coms",computers);
        return "/ComputerIndex.html";
    }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值