【问题标题】:Thymeleaf th:field overwrites th:valueThymeleaf th:field 覆盖 th:value
【发布时间】:2021-03-29 01:48:36
【问题描述】:

我刚刚发现th:field 属性覆盖了th:value 属性。

在我的th:each 中,我想覆盖th:field 为我生成的值。有谁知道如何做到这一点?

提前致谢。

<ul id="userGroupContainer">
	<li class="clickable unselected" th:each="u, rowStat : ${userNotInGroup}" th:if="${u.id}">
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].id}" th:value="${u.id}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].displayName}" th:value="${u.displayName}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].username}" th:value="${u.username}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="*{users[__${rowStat.index}__].emailAddress}" th:value="${u.emailAddress}" />
								<span th:text="${u.displayName}"></span>
	</li>
</ul>

【问题讨论】:

    标签: java html thymeleaf


    【解决方案1】:

    Thymeleaf th:field 生成 3 个 html 属性 idnamevalue

    对于您的情况,不要使用th:field,而是使用th:idth:nameth:value,如下所示。

    <input type="text" th:id="${'users'+__${rowStat.index}__+'.id'}" th:name="${'users['+__${rowStat.index}__+'].id'}" th:value="${u.id}" readonly="readonly" hidden="hidden" disabled="disabled"/>
    <input type="text" th:id="${'users'+__${rowStat.index}__+'.displayName'}" th:name="${'users['+__${rowStat.index}__+'].displayName'}" th:value="${u.displayName}" readonly="readonly" hidden="hidden" disabled="disabled"/>
    

    【讨论】:

      【解决方案2】:

      就像上面所说的那样,你应该将th:field 更改为th:idth:nameth:value。我想补充一点,我的th:idth:name 的值只是我的实体中列的名称(在我的例子中是testID)。希望下面的示例对任何人都有帮助。

      <td><input th:value="${request.testID}" th:id="testID" th:name="testID"/></td>
      

      【讨论】:

        猜你喜欢
        • 2015-03-07
        • 2018-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-20
        • 2018-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多