Java 已解决[org.springframework.web.HttpRequestMethodNotSupportedException:请求方法'POST'不受支持]
我有两个列表,一个是用户列表,另一个是团队列表。我可以从列表中选择任何用户,也可以选择任何团队。 但无法将用户添加到团队。 按下按钮时,错误得到解决[org.springframework.web.HttpRequestMethodNotSupportedException:Request方法'POST'不受支持] 使用者 团队 admin.htmlJava 已解决[org.springframework.web.HttpRequestMethodNotSupportedException:请求方法'POST'不受支持],java,spring,rest,thymeleaf,Java,Spring,Rest,Thymeleaf,我有两个列表,一个是用户列表,另一个是团队列表。我可以从列表中选择任何用户,也可以选择任何团队。 但无法将用户添加到团队。 按下按钮时,错误得到解决[org.springframework.web.HttpRequestMethodNotSupportedException:Request方法'POST'不受支持] 使用者 团队 admin.html <form th:action="@{/admin/team/user/}"th:object="${userTeamForm}" me
<form th:action="@{/admin/team/user/}"th:object="${userTeamForm}" method="POST">
<div class="form-group blu-margin">
<select class="form-control" id="addUser">
<option value="0">select user</option>
<option th:each="user : ${users}" th:value="${user.name}" th:text="${user.name}"></option>
</select>
<select class="form-control" id="addTeam">
<option value="0">select team</option>
<option th:each="team : ${teams}" th:value="${team.name}" th:text="${team.name}"></option>
</select>
</div>
<br/>
<input type="submit" value="Add User to Team" />
</form>
抱歉,我没有注意到方法描述中的}。 我找了两天的问题
@RequestMapping(value = "/admin/team/user}", method = RequestMethod.POST,
不应该有}个后用户请共享完整的堆栈跟踪。事实上,这是整个堆栈。按下按钮时,错误得到解决[org.springframework.web.HttpRequestMethodNotSupportedException:Request方法'POST'不受支持]
@RequestMapping(value = "/admin/team/user}", method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public String addUserToTeam(@PathVariable String userName, @PathVariable String teamName,Model model, @ModelAttribute("userTeamForm") @Validated UserTeamForm userTeamForm,
BindingResult result, final RedirectAttributes redirectAttributes) {
Team team = teamRepository.findTeamByName(teamName).orElseThrow(() -> new NoSuchTeamException("Team not found"));
Users user = userRpRepository.findUsersByName(userName)
.orElseThrow(() -> new NoSuchUserException("User not found"));
user.setTeam(team);
userRpRepository.save(user);
return "userTeam";
}
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminPage(Model model) {
model.addAttribute("userTeamForm",new UserTeamForm());
....
return "admin";
}
<form th:action="@{/admin/team/user/}"th:object="${userTeamForm}" method="POST">
<div class="form-group blu-margin">
<select class="form-control" id="addUser">
<option value="0">select user</option>
<option th:each="user : ${users}" th:value="${user.name}" th:text="${user.name}"></option>
</select>
<select class="form-control" id="addTeam">
<option value="0">select team</option>
<option th:each="team : ${teams}" th:value="${team.name}" th:text="${team.name}"></option>
</select>
</div>
<br/>
<input type="submit" value="Add User to Team" />
</form>
public class UserTeamForm {
private String userName;
private String teamName;
get/set
@RequestMapping(value = "/admin/team/user}", method = RequestMethod.POST,