Alex Rivera | Logout

Learning Spring's @RequestBody and @RequestParam annotations

Asked 2010-07-26T17:32:00.380
17

I'm editing a web project that uses Spring and I need to add some of Spring's annotations. Two of the ones I'm adding are @RequestBody and @RequestParam. I've been poking around a little and found this, but I still don't completely understand how to use these annotations.

Could anyone provide an example?

Edit
Report

1 Answer

18

Controller example:

@Controller
class FooController {
    @RequestMapping("...")
    void bar(@RequestBody String body, @RequestParam("baz") baz) {
        //method body
    }
}

@RequestBody: variable body will contain the body of the HTTP request

@RequestParam: variable baz will hold the value of request parameter baz

answered 2010-07-26T17:43:58.213

Your Answer