1, @PathVariable
When using @RequestMapping URI template style mapping, i.e. someUrl / {paramId}, at this time may be bound by @Pathvariable paramId annotations on process parameter values to pass over it.
@Controller @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { @RequestMapping("/pets/{petId}") public void findPet(@PathVariable String ownerId,@PathVariable String petId, Model model) { // implementation omitted } }
The code above and petId values of variables ownerId the URI template, bound to the parameters of the method. If the uri template variable name and the name of the method parameters need to bind not, you need to specify the name uri template in the @PathVariable ( "name").
2、 @RequestHeader和@CookieValue
@RequestHeader annotations can request value Request header portion bound to the parameters of the method.
This is the header part of a Request:
Host localhost:8080
Accept text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language fr,en-gb;q=0.7,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
@RequestMapping("/displayHeaderInfo.do") public void displayHeaderInfo(@RequestHeader("Accept-Encoding") String encoding, @RequestHeader("Keep-Alive") long keepAlive) { //...
The above code, the value of the Accept-Encoding request header portion, bound to the encoding parameters, and Keep-Alive header value is bound to the parameter keepAlive.
@CookieValue can Request header value on the cookie bound to the parameters of the method.
Cookie value, for example, the following:
// The 415A4AC178C59DACE0B2C9CA727CDD84 = JSESSIONID @RequestMapping ( "/ displayHeaderInfo.do" ) public void displayHeaderInfo (@CookieValue ( "JSESSIONID" ) String cookie) { // ... } // i.e. the value of the parameter to bind JSESSIONID cookie .
3、@RequestParam, @RequestBody
@RequestParam
Commonly used to handle simple type of binding, the annotation has two attributes: value, required; value is used to specify the value to be passed id name, required to indicate whether the parameter must be bound;
@RequestBody
The annotation process used to Content-Type: application / json, application / xml etc;