除非块从未执行过

时间:2018-04-11 03:26:59

标签: spring thymeleaf

我使用百里香叶3和我的除非块永远不会被执行

<th:block th:if="${products.productTypes gt 8 and products.productTypes lt 12}">
    <div th:replace="fragments/products/sub-granulates"/>
</th>
<th:unless="${products.productTypes gt 8 and products.productTypes lt 12}">
    <div th:replace="fragments/products/sub-traditional-products"/>
</th>

任何建议?

2 个答案:

答案 0 :(得分:1)

你的th:bloc没有关闭,除非,没有th:block

答案 1 :(得分:1)

你的百里香是畸形的...应该是这样的:

<th:block th:if="${products.productTypes gt 8 and products.productTypes lt 12}">
    <div th:replace="fragments/products/sub-granulates"/>
</th:block>

<th:block th:unless="${products.productTypes gt 8 and products.productTypes lt 12}">
    <div th:replace="fragments/products/sub-traditional-products"/>
</th:block>

我相信自从thymeleaf 3以来,您还可以将代码简化为:

<div th:replace="${products.productTypes gt 8 and products.productTypes lt 12} ? ~{fragments/products/sub-traditional-products} : ~{fragments/products/sub-traditional-products}"/>