Spring Controller 404 retuned after POST method Invoked

后端 未结 2 423
野趣味
野趣味 2021-01-11 16:19

I have a Spring controller which is being called from JQuery.post(). When it is called the controller\'s method is invoked and returns. But then, in the background, Spring c

2条回答
  •  一整个雨季
    2021-01-11 16:59

    Solved.

    The problem was as #CodeChimp suggested, except I still wanted a void return type.

    I added the @ResponseBody to the addPerson method and everything worked fine:

    @RequestMapping(value="put", method = RequestMethod.POST)
    **@ResponseBody**
    public void addPerson(@ModelAttribute("person") Person person){
      System.out.println(">>>>>>> person: " + person);
      System.out.println(">>>>>>>>> " + person.getFirstName());
      people.add(person);
    }
    

    The clue came from http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-responsebody. Although the documentation is not clear what happens with a void return. Just tried it and it worked.

提交回复
热议问题