Dispatcherservlet after a Web request is accepted, the request is sent to the different controller classes of the @controller annotation declaration.
This scheduling process relies on various @requestmapping annotations declared in the Controller class and its handler methods.
In Spring MVC, Web requests are mapped to handlers through one or more @requestmapping annotations declared in the controller class.
The handler mappings match URLs based on relative paths to the context path (Web App context path) and the servlet path (the path mapped to Dispatcherservlet).
The simplest strategy for using @requestmapping annotations is to directly modify the handler method. To do this, each handler method is declared with a @requestmapping annotation that contains a URL pattern.
If the @requestmapping annotation of the method matches the requested Url,dispatcherservlet, the request is sent to this method for processing.
@Controller
Control class
@Autowired
Instance of control inversion generation control class
@RequestMapping ("/member/add")
Method 1
@RequestMapping (value={"/member/remove", "/member/delete"}, Method=requestmethod.get)
Method 2
Another kind
@Controller
@RequestMapping ("/member/*")
Control class
@Autowired
Instance of control inversion generation control class
@RequestMapping ("Add")
Method 1
@RequestMapping (value={"Remove", "delete"}, Method=requestmethod.get)
Method Two
@RequestMapping ("Display/{user}")
Method Three (@RequestParam ("MemberName") string membername, @PathVariable ("user") string user)
@RequestMapping
Method Four
Method Five
For method Three, if the accepted request form is/member/display/jdoe, the method accesses the user variable with the JDoe value
The @requestmapping annotation is used for method four, but the URL value is missing because the class level uses the/member/* URL wildcard, which is performed as an all-in-one method.
Any URL request, such as/MEMBER/ABCDEFG or/member/randomrout, will trigger this method.
The last method has no @requestmapping annotations, meaning that this method is a tool that has no effect on spring MVC.
Mapping requests by HTTP request type
By default, @RequestMapping annotations assume that all inbound requests are of the HTTP get type. However, when an inbound request is a different HTTP type, it is necessary to explicitly specify the type in the @requestmapping annotation.
@RequestMapping (method = Requestmethod.post)
Public String SubmitForm (@ModelAttribute ("member") member member, bindingresult result, model model) {
......
}
Mapping requests with @requestmapping