在GET方法中我将这些添加到模型中:
model.addAttribute("team", team);
model.addAttribute("players", team.getPlayers());
model.addAttribute("inviting", new InvitingPlayerToTeam());
使用此模型的视图片段:
<div id="news" th:fragment="playerList">
<span>Nazwa: </span>
<span th:text="${team.name}">nazwa teamu</span>
<br>
<span th:each="player : ${players}" th:utext="${player.username} + '</br>'">-</span>
<br><br>
<form method="POST" th:action="@{/team/invitePlayer}" th:object="${inviting}">
Nazwa <input type="text" th:field="*{username}">
<input type="hidden" th:field="*{teamId}" th:value="${team.id}">
<br>
<input type="submit" value="Zaproś">
</form>
</div>
有什么问题?在帖子方法字段中,inviting.username
具有良好的价值,但inviting.teamId
为0
。问题在哪里?
答案 0 :(得分:0)
只需删除th:value="${team.id}"
即可。您无需再次设置此值。
您应该在控制器中使用正确的值设置表单支持bean。
inviting.setTeamId(...)