百里香叶的隐藏输入值错误

时间:2016-06-26 20:56:43

标签: java spring thymeleaf

在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.teamId0。问题在哪里?

1 个答案:

答案 0 :(得分:0)

只需删除th:value="${team.id}"即可。您无需再次设置此值。

您应该在控制器中使用正确的值设置表单支持bean。

inviting.setTeamId(...)