将数组作为 Thymeleaf 片段中的参数传递

Big*_*igJ 3 thymeleaf spring-boot

是否可以将数组传递给片段,如下所示:

<div th:replace="fragments :: test_fragment( {'one', 'two', 'three'} )"></div>
Run Code Online (Sandbox Code Playgroud)

并像这样迭代片段:

<div th:fragment="test_fragment(numberArray)">

    <span th:each="number : ${numberArray}" th:text="${number}"></span>

</div>
Run Code Online (Sandbox Code Playgroud)

另外,多维数组也可能吗?

我在 Spring Boot 2.0 项目中使用 Thymeleaf。

Ala*_*ruz 5

对的,这是可能的。下面的代码应该可以解决问题。唯一的区别是${}在数组外部添加了 , 。

<div th:replace="fragments :: test_fragment(${ {'one', 'two', 'three'} })"></div>
Run Code Online (Sandbox Code Playgroud)