How to explicitly obtain post data in Spring MVC?

后端 未结 3 1611
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 15:14

Is there a way to obtain the post data itself? I know spring handles binding post data to java objects. But, given two fields that I want to process, how can I obtain that d

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 15:46

    If you are using one of the built-in controller instances, then one of the parameters to your controller method will be the Request object. You can call request.getParameter("value1") to get the POST (or PUT) data value.

    If you are using Spring MVC annotations, you can add an annotated parameter to your method's parameters:

    @RequestMapping(value = "/someUrl")
    public String someMethod(@RequestParam("value1") String valueOne) {
     //do stuff with valueOne variable here
    }
    

提交回复
热议问题