thymeleaf遍历时合并单元格
2019-06-11 20:47
2506 查看
在开发中会遇到一个订单下有多个商品,但是他们的订单号一样,这时就需要在遍历时把订单号单元格合并起来.
没合并之前:
没合并之前代码:
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>thymeleaf单元格合并</title> </head> <body> <table border="1"> <thead> <tr> <th>订单号</th> <th>商品名称</th> <th>商品价格</th> </tr> </thead> <tr th:each="order:${orderList}"> <td><span th:text="${order.oId}">订单号</span></td> <td><span th:text="${order.shopNmae}">商品名称</span></td> <td><span th:text="${order.shopMoney}">商品价格</span></td> </tr> </table> </body> </html>
合并之后:
合并之后代码:
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>thymeleaf单元格合并</title> </head> <body> <table border="1"> <thead> <tr> <th>订单号</th> <th>商品名称</th> <th>商品价格</th> </tr> </thead> <!-- 状态变量定义在一个th:每个属性和包含以下数据: 1.当前迭代索引,从0开始。这是索引属性。index 2.当前迭代索引,从1开始。这是统计属性。count 3.元素的总量迭代变量。这是大小属性。 size 合并单元格使用rowspan --> <tr th:each="order,star:${orderList}"> <!-- 遍历第一次的时候输入订单号 --> <span th:if="${star.index} == 0"> <td th:rowspan="${star.size}"><span th:text="${order.oId}">订单号</span></td> <td><span th:text="${order.shopNmae}">商品名称</span></td> <td><span th:text="${order.shopMoney}">商品价格</span></td> </span> <!-- 第一次之后就不需要了 --> <span th:if="${star.index} != 0"> <td><span th:text="${order.shopNmae}">商品名称</span></td> <td><span th:text="${order.shopMoney}">商品价格</span></td> </span> </tr> </table> </body> </html>
相关文章推荐
- thymeleaf-js获取当前用户以及遍历ajax的json数组
- thymeleaf循环遍历
- Thymeleaf模版遍历JSON对象
- thymeleaf遍历map集合输出key+value
- Thymeleaf基础 遍历List、Map、List<map>、Map<List>
- spring boot 与 thymeleaf (3): 设置属性、条件、遍历、局部变量、优先级、内联语法
- (七)Thymeleaf的 th:* 属性之—— th: ->设值& 遍历迭代& 条件判断
- thymeleaf模板 遍历对象
- excel 数据读取,数据遍历,获取日期数据和合并单元格数据
- Thymeleaf模板引入遍历枚举
- java鬼混笔记:springboot之thymeleaf 3:th:each遍历
- thymeleaf循环遍历
- C# for循环遍历字典里面的所有元素
- LeetCode Binary Tree Postorder Traversal(二叉树的后序遍历 非递归实现)
- freemarker 直接使用List来遍历set集合,可能会报错
- 树结构的动态建立和前序、中序、后序遍历
- GetDIBits 遍历位图 获取像素的颜色值(RGB)
- 第十二周项目5-迷宫问题之图深度优先遍历解法
- Thymeleaf【第一篇】 结合springmvc
- Bundle的遍历方法