14.2 订单详情

现在,对订单详情页面,我们会频繁使用星号语法:

  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <title>Good Thymes Virtual Grocery</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <link rel="stylesheet" type="text/css" media="all"
  7. href="../../../css/gtvg.css" th:href="@{/css/gtvg.css}" />
  8. </head>
  9. <body th:object="${order}">
  10. <h1>Order details</h1>
  11. <div>
  12. <p><b>Code:</b> <span th:text="*{id}">99</span></p>
  13. <p>
  14. <b>Date:</b>
  15. <span th:text="*{#calendars.format(date,'dd MMM yyyy')}">13 jan 2011</span>
  16. </p>
  17. </div>
  18. <h2>Customer</h2>
  19. <div th:object="*{customer}">
  20. <p><b>Name:</b> <span th:text="*{name}">Frederic Tomato</span></p>
  21. <p>
  22. <b>Since:</b>
  23. <span th:text="*{#calendars.format(customerSince,'dd MMM yyyy')}">1 jan 2011</span>
  24. </p>
  25. </div>
  26. <h2>Products</h2>
  27. <table>
  28. <tr>
  29. <th>PRODUCT</th>
  30. <th>AMOUNT</th>
  31. <th>PURCHASE PRICE</th>
  32. </tr>
  33. <tr th:each="ol,row : *{orderLines}" th:class="${row.odd}? 'odd'">
  34. <td th:text="${ol.product.name}">Strawberries</td>
  35. <td th:text="${ol.amount}" class="number">3</td>
  36. <td th:text="${ol.purchasePrice}" class="number">23.32</td>
  37. </tr>
  38. </table>
  39. <div>
  40. <b>TOTAL:</b>
  41. <span th:text="*{#aggregates.sum(orderLines.{purchasePrice * amount})}">35.23</span>
  42. </div>
  43. <p>
  44. <a href="list.html" th:href="@{/order/list}">Return to order list</a>
  45. </p>
  46. </body>
  47. </html>

这儿没有什么新东西,除了这个内嵌的对象选择:

  1. <body th:object="${order}">
  2. ...
  3. <div th:object="*{customer}">
  4. <p><b>Name:</b> <span th:text="*{name}">Frederic Tomato</span></p>
  5. ...
  6. </div>
  7. ...
  8. </body>

这儿的 *{name}等价于:

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