@RequestMapping 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 process the request action, which can be used for classes and methods.
@RequestMapping can be used to annotate a controller class, in which case all methods are 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. The sample code is as follows:
@Controller @requestmapping (value = "/user" public class usercontroller{@RequestMapping (value = "/register" ) public String Register () { return "register" ; } @RequestMapping (Value = "/login" public String login () { return "Login" Span style= "COLOR: #000000" >; }}
Because the Usercontroller class adds a @requestmapping annotation for value= "/user", all related paths are added "/user", and the method is mapped to the following request URL (Uniform Resource Locator):
Http://localhost:8080/user/register
Http://localhost:8080/user/login
Use the @requestmapping annotation to specify the properties shown in the following table:
| Property |
Type |
Whether it is necessary |
Description |
| Value |
String[] |
Whether |
Used to map the actual address of the specified request to the method |
| Name |
String |
Whether |
Specify an alias for the mapped address |
| Method |
Requestmethod[] |
Whether |
MAP Specifies the type of method requested, including get, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE |
| Consumes |
String[] |
Whether |
Specifies the type of submission to process the request (Content-type), such as Application/json, text/html, and so on |
| Produces |
String[] |
Whether |
Specifies the type of content returned, and the content type that is returned must be the one contained in the request header (Accept) |
| Params |
String[] |
Whether |
Specifies that some parameter values must be included in the request for the method to handle |
| Headers |
String[] |
Whether |
Specifies that some specified header values must be included in the request for the method to process requests |
| Path |
String[] |
Whether |
In a servlet environment only: URI path mappings (for example: "/mypath.do"). At the method level, relative paths are supported (for example: "Edit.do") |
@RequestMapping annotations