我可以将List
绑定为object
中thymleaf
的属性,但此列表的属性又为List
。这给了我解析错误:
绑定列表:
<form th:object="${obj}" th:action="@{/list}" action="void(0)" method="post">
<tr>
<td th:field="*{id}" th:text="${obj.id}" />
</tr>
<tr th:each="l , i : ${obj.someList}">
<input type="hidden" th:field="*{someList[__${i.index}__].something}" />
</tr>
<input type="submit" class="btn btn-success" />
</form>
列表再次有一个列表:
public class Foo {
private int id;
private List<Some> someList;
//setter getter
}
public class Some {
private int sid;
private List<SomeChild> anotherList;
}
我尝试了以下方法:
<form th:object="${obj}" th:action="@{/list}" action="void(0)" method="post">
<tr>
<td th:field="*{id}" th:text="${obj.id}" />
</tr>
<tr th:each="l , i : ${obj.someList}">
<input type="hidden" th:field="*{someList[__${i.index}__].sid}" />
<!-- till above line it works -->
<th:block th:each="m, j : ${obj.someList.get(__${i.index}__).anotherList}">
<!-- till above line no error -->
<input type="hidden" th:field="*{someList[__${i.index}__].getAnotherList().get(__${j.index}__).id}" />" />
<!-- error on above line / no readable property -->
</th:block>
</tr>
<input type="submit" class="btn btn-success" />
</form>
我尝试了所有可能的组合,通过索引/ get()和field / getters访问列表,但没有运气。请帮忙。