Thymeleaf教程 (十一) 一些商店的过多的模板页面例子

订单列表

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Good Thymes Virtual Grocery</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="all"
        href="../../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
    </head>
<body>
    <h1>Order list</h1>
    <table>
        <tr>
            <th>DATE</th>
            <th>CUSTOMER</th>
            <th>TOTAL</th>
            <th></th>
        </tr>
        <tr th:each="o : ${orders}" th:class="${oStat.odd}? 'odd'">
            <td th:text="${#calendars.format(o.date,'dd/MMM/yyyy')}">13 jan 2011</td>
            <td th:text="${o.customer.name}">Frederic Tomato</td>
            <td th:text="${#aggregates.sum(o.orderLines.{purchasePrice * amount})}">23.32</td>
            <td>
                <a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>
            </td>
        </tr>
    </table>
    <p>
        <a href="../home.html" th:href="@{/}">Return to home</a>
    </p>
    </body>
</html>

这里比较特殊的在于这句

<td th:text="${#aggregates.sum(o.orderLines.{purchasePrice * amount})}">23.32</td>

意思是orderlines这个list对象中的purchasePrice和amount相乘并返回数值到list对像中,并通过aggregates.sum()函数相加。

订单详情

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Good Thymes Virtual Grocery</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="all"
        href="../../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
    </head>
    <body th:object="${order}">
        <h1>Order details</h1>
        <div>
            <p><b>Code:</b> <span th:text="*{id}">99</span></p>
            <p>
            <b>Date:</b>
                <span th:text="*{#calendars.format(date,'dd MMM yyyy')}">13 jan 2011</span>
            </p>
        </div>
        <h2>Customer</h2>
        <div th:object="*{customer}">
            <p><b>Name:</b> <span th:text="*{name}">Frederic Tomato</span></p>
            <p>
            <b>Since:</b>
                <span th:text="*{#calendars.format(customerSince,'dd MMM yyyy')}">1 jan 2011</span>
            </p>
        </div>
        <h2>Products</h2>
        <table>
            <tr>
                <th>PRODUCT</th>
                <th>AMOUNT</th>
                <th>PURCHASE PRICE</th>
            </tr>
            <tr th:each="ol,row : *{orderLines}" th:class="${row.odd}? 'odd'">
                <td th:text="${ol.product.name}">Strawberries</td>
                <td th:text="${ol.amount}" class="number">3</td>
                <td th:text="${ol.purchasePrice}" class="number">23.32</td>
            </tr>
        </table>
        <div>
            <b>TOTAL:</b>
            <span th:text="*{#aggregates.sum(orderLines.{purchasePrice * amount})}">35.23</span>
        </div>
        <p>
            <a href="list.html" th:href="@{/order/list}">Return to order list</a>
        </p>
    </body>
</html>

就这里特殊一点

<body th:object="${order}">
...
    <div th:object="*{customer}">
    <p><b>Name:</b> <span th:text="*{name}">Frederic Tomato</span></p>
    ...
    </div>
...
</body>

*{name}在这里的意思是

<p><b>Name:</b> <span th:text="${order.customer.name}">Frederic Tomato</span></p>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值