1. a query parameter value
@RequestParam("name")
2. a group of query parameter values
//A custom JavaBean with a getName()/setName() pair for each parameter
@RequestMapping(value="group")
public @ResponseBody String withParamGroup(JavaBean bean) {
return "Obtained parameter group " + bean;
}
3. A path element value
//@PathVariable("var")
@RequestMapping(value="path/{var}")
public @ResponseBody String withPathVariable(@PathVariable String var) {
return "Obtained 'var' path variable value '" + var + "'";
}
4. A request header value
//@RequestHeader("name")
@RequestMapping(value="header")
public @ResponseBody String withHeader(@RequestHeader String Accept) {
return "Obtained 'Accept' header '" + Accept + "'";
}
5. A cookie value
//@CookieValue("name")
@RequestMapping(value="cookie")
public @ResponseBody String withCookie(@CookieValue String openid_provider) {
return "Obtained 'openid_provider' cookie '" + openid_provider + "'";
}
6. The request body
//@RequestBody
@RequestMapping(value="body", method=RequestMethod.POST)
public @ResponseBody String withBody(@RequestBody String body) {
return "Posted request body '" + body + "'";
}
7. The request body and any request header
//HttpEntity<T>
@RequestMapping(value="entity", method=RequestMethod.POST)
public @ResponseBody String withEntity(HttpEntity<String> entity) {
return "Posted request body '" + entity.getBody() + "'; headers = " + entity.getHeaders();
}