Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 已解决[org.springframework.web.HttpRequestMethodNotSupportedException:请求方法'POST'不受支持]_Java_Spring_Rest_Thymeleaf - Fatal编程技术网

Java 已解决[org.springframework.web.HttpRequestMethodNotSupportedException:请求方法'POST'不受支持]

Java 已解决[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

我有两个列表,一个是用户列表,另一个是团队列表。我可以从列表中选择任何用户,也可以选择任何团队。 但无法将用户添加到团队。 按下按钮时,错误得到解决[org.springframework.web.HttpRequestMethodNotSupportedException:Request方法'POST'不受支持]

使用者

团队

admin.html

  <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,