如何使用Thymeleaf动态设置HTML元素的id属性

Laz*_*rov 23 html rest spring thymeleaf

假设我有一个对象:$ {object}

我有以下表格:

<form id="{{'myForm' + object.id}" class="some class"
      th:action="@{/doSomething}" method="post">
    ....
</form>
Run Code Online (Sandbox Code Playgroud)

如果我们假设object.id为'1',我的目标是设置id ="myForm1".

PS:我写它的方式正在研究Angular JS.

Ser*_*nso 43

你必须使用th:id属性:

<form th:id="'myForm' + ${object.id}" class="some class" th:action="@{/doSomething}" method="post">
// *** Other code here ***
</form>
Run Code Online (Sandbox Code Playgroud)