使用th:object而不使用模型

mnowg1ta  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(340)

我想和你一起做表格 th:object 对于数组的每个元素。但我得到了错误。问题是 th:object 仅用于保存在模型上的对象。如何使用 th:objectth:field 在…上 th:each ,或其他解决方法?

<tr th:each="sect: ${process.sectionData}" th:if="${sect.sectionType==1}">
       <form th:action="@{'/process/section/save/' + ${sect.id} }" method="post" th:object="${sect}">
          <td>
             <button>
                save
             </button>
          </td>
          <td>
             <input
                 type="text"
                 th:field="*{sect.name}"
                 class="m-inline"
                 placeholder="Страна проведения"/>
          </td>
        </form>
</tr>
iih3973s

iih3973s1#

th:field 只是设置 name , id ,及 value 输入字段的名称。您应该能够做到这一点并使其正常工作:

<tr th:each="sect: ${process.sectionData}" th:if="${sect.sectionType==1}">
  <form th:action="@{'/process/section/save/' + ${sect.id}}" method="post">
    <td>
       <button>save</button>
    </td>

    <td>
       <input
          type="text"
          name="name"
          th:value="${sect.name}"
          class="m-inline"
          placeholder="Страна проведения" />
    </td>
  </form>
</tr>

相关问题