Can @RequestParam be used on non GET requests?

后端 未结 3 1804
一向
一向 2021-01-14 00:29

Spring documentation says:

Use the @RequestParam annotation to bind request parameters to a method parameter in your controller.

AFA

3条回答
  •  温柔的废话
    2021-01-14 01:07

    Yes it works perfectly with post method too. you can mention the method attribute of @RequestParam as RequestMethod=POST. Here is the code snippet

    @RequestMapping(value="/register",method = RequestMethod.POST)
    
    public void doRegister
    (
    
        @RequestParam("fname") String firstName,
        @RequestParam("lname")String lastName,
        @RequestParam("email")String email,
        @RequestParam("password")String password 
    )
    

提交回复
热议问题