Java Thymeleaf中的多维数组搜索?

Java Thymeleaf中的多维数组搜索?,java,arrays,for-loop,thymeleaf,Java,Arrays,For Loop,Thymeleaf,是否可以检查二维阵列上是否存在特定元素 <div th:each="employee, i : ${company.employees}"> <div th:each="duty, j : ${employee.duties}"> <div class="custom-control custom-checkbox my-1 mr-sm-2"> <input type="checkbox" name="duties"

是否可以检查二维阵列上是否存在特定元素

<div th:each="employee, i : ${company.employees}">
<div th:each="duty, j : ${employee.duties}">
    <div class="custom-control custom-checkbox my-1 mr-sm-2">
        <input type="checkbox" name="duties"
               th:id="${j.index}" th:value="${j.index}"
               th:checked="${#arrays.contains(${company.tasks[i.index][]}, ${duty.id})}" />
        <label th:for="${j.index}" th:text="${j.index}"></label>
    </div>
</div>
</div>

Java等价物应为:

for (int i=0; i<company.getEmployees().length; i++)
    for (Duty duty : company.getEmployees().[i].getDuties())
       boolean checked = company.getTasks()[i].contains(duty.id); 
       // Contains, method that checks whether element exists on array
for(inti=0;i不要这样做

Thymeleaf和其他前端框架不适用于数据提取和转换,数据提取和转换应在较低的1层或2层执行。这些框架的作用是绑定、发布和显示已转换的模型,该模型在最佳情况下应已处于最终形式


我建议您在将数据公开给模板之前执行此条件数据提取。模板内部只需要一次迭代。

clearify what you want