我使用 spring boot thymeleaf 和 mySQL DB 我有 3 個物體:
- 類別
- 子類別
- 產品
當前表
我想在表格中顯示產品的總和
這是顯示子類別總和的代碼:
<tbody>
<tr th:each="category : ${categories}">
<td th:text="${category.name}" />
<td th:text="${#lists.size(category.subCategories)}" />
</tr>
</tbody>
uj5u.com熱心網友回復:
您可以使用集合投影和聚合函式來完成此操作:
<tbody>
<tr th:each="category : ${categories}">
<td th:text="${category.name}" />
<td th:text="${#lists.size(category.subCategories)}" />
<td th:text="${#aggregates.sum(category.subCategories.![#lists.size(products)])}" />
</tr>
</tbody>
運算式category.subCategories.![#lists.size(products)]生成子類別中的產品串列,您可以使用 對其進行求和#aggregates.sum。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/450857.html
