Java thymileaf-从循环到操作url获取变量

Java thymileaf-从循环到操作url获取变量,java,thymeleaf,Java,Thymeleaf,我对此代码有问题: <form method="post" th:action="@{/categories/category}"> <select name="category"> <option th:each="category : ${categoriesList}" th:text="${category.name}" th:value="${category.id}"/> </select> &l

我对此代码有问题:

<form method="post" th:action="@{/categories/category}">
    <select name="category">
        <option th:each="category : ${categoriesList}" th:text="${category.name}" th:value="${category.id}"/>
    </select>
    <select name="language">
        <option value="ENGLISH">Angielski</option>
        <option value="GERMAN">Niemiecki</option>
        <option value="FRENCH">Francuski</option>
    </select>
    <input type="submit"/>
</form>

安吉尔斯基
尼米耶基
弗兰楚斯基
我不知道如何在第一行代码的url中插入类别ID而不是“category”。所以看起来应该是这样的:

<form method="post" th:action="@{/categories/CATEGORY_ID}">


是否有任何选项可以根据从选择中选择的选项动态链接它?

th:each
向上移动一级到
select
元素。

在Thymeleaf中,您不能在定义它的同一标记中使用变量。 相反,您可以使用不可见的th:block标记:

<select name="category">
  <th:block th:each="category : ${categoriesList}">
    <option th:text="${category.name}" th:value="${category.id}"/>
  </th:block>
</select>


在thymeleaf中无法执行此操作。你必须使用javascript。你不能使用带有CATEGORY\u ID的input type=“hidden”吗?如果答案对你有帮助,你应该接受答案。这会重复select标记,这不是他想要的。