Can I use @Requestparam annotation for a Post request?

前端 未结 5 858
名媛妹妹
名媛妹妹 2020-12-02 19:10

I have this controller method:

@PostMapping(
        value = \"/createleave\",
        params = {\"start\",\"end\",\"hours\",\"username\"})
public void creat         


        
5条回答
  •  孤城傲影
    2020-12-02 19:40

    Well, I think the answer by @Synch is fundamentally wrong, and not the question being asked.

    1. First of all, I use @RequestParam in a lot of scenarios expecting either GET or POST HTTP messages and I'd like to say, that it works perfectly fine;
    2. POST Message's data payload (body), which is referred to the most voted answer (again, by @Synch) is actually the text data, which can perfectly legally be paramname=paramvalue key-value mapping(s) alike (see POST Message Body types here);
    3. docs.spring.io, an official source for Spring Documentation, clearly states, that:

      In Spring MVC, "request parameters" map to query parameters, form data, and parts in multipart requests.

    So, I think the answer is YES, you can use @RequestParam annotation with @Controller class's method's parameter, as long as that method is request-mapped by @RequestMapping and you don't expect Object, this is perfectly legal and there's nothing wrong with it.

提交回复
热议问题