我试图将隐藏的输入值放入表单中,但字段始终为空。
<form th:action="@{/user/subject/join}" th:object="${joinSubjectDTO}" method="post">
<table>
<tr>
<td>Password to subject:</td>
<td><input type="password" th:field="*{password}" /></td>
<td><input type="hidden" th:field="*{subjectId}" th:value="${subject.id}"/></td>
</tr>
<tr>
<td><button type="submit">Join</button></td>
</tr>
</table>
</form>
有人可以帮我解决这个问题吗?
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JoinSubjectDTO {
private Integer subjectId;
private String password;
}
我正在添加 JoinSubjectDTO 类。
最佳答案
尝试在线下。无需带td标签。将隐藏标签写在表格之外。也不要指定 th:value,因为 t:field 本身就是 id、名称和值。
<input type="hidden" th:field="*{subjectId}">
关于java - Thymeleaf 隐藏输入值始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56293061/