There are many annotations for parameter binding in Spring MVC, all in the Org.springframework.web.bind.annotation package, which can be divided into four classes based on the different parts of the request they handle (mainly on common types)
>> Note on the body part of the request: @RequestParam, @RequestBody
>> handling annotations in reuqest URL section: @PathVariable
>> handling notes in the header section of the request: @RequestHeader, @CookieValue
>> handling attribute types of annotations: @SessionAttibute, @ModelAttribute
@RequestMapping notes:
* * @RequestMapping Although under org.springframework.web.bind.annotation, but strictly speaking, he does not belong to the parameter binding annotations
Developers need to develop appropriate processing methods for each request action within the controller. The org.springframework.web.bind.annotation.RequestMapping annotation type indicates which class or method spring uses to handle the request action, which can be used for a class or method.
@RequestMapping can be used to annotate a controller class, in which case all methods will be mapped to requests relative to the class level, indicating that all requests processed by the controller are mapped to the path indicated by the Value property
= "/user")publicclass usercontroller{ = "/register") Public String Register () { return "register"; } = "/login") public String Login () { return "Login"; } }
Request Url:http://localhost:8080/user/register
Http://localhost:8080/user/login
>>1.value Property
@RequestMapping (value = "/hello") public modelandview Hello () { return ...;}
The instance uses the Value property of the @requestmapping comment to map the URL to the method, in which case the Hello is mapped to the Hello method, which is handled by the Hello method when the application is accessed using the following URL:
Http://localhost:8080/context/hello
Because the Value property is the default property of the @requestmapping comment, the property name can be omitted if there is only a unique property
@RequestMapping (value = "/hello") @RequestMapping ("/hello")
But if you have more than one property, you must write the Value property name
The value of the Value property can also be an empty string, at which point the method is mapped to the following request URL:
Http://localhost:8080/context
>>2.method Property
This property is used to indicate that the method only handles those HTTP request methods
@RequestMapping (value = "/hello" method = "Requestmethod.post")
The code above indicates that the method only supports post requests
You can also support multiple HTTP request modes at the same time:
@RequestMapping (value = "/hello", method = {Requestmethod.post,requestmethod.get})
If you do not specify the method property value, the request processing method can handle any HTTP request mode
@RequestMapping annotations