How Spring MVC specifies the URL mapping for the processor
This article mainly shows you "how Spring MVC specifies URL mapping for processors", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how Spring MVC assigns URL mapping to processors".
Specify the URL mapping for the processor
This is an essential step in writing a controller class designed to handle one or more specific requests. Spring MVC provides the @ RequestMapping annotation to specify the URL mapping. Such as:
This step maps the URL schema / login and processes it with annotations or annotation classes. When the @ RequestMapping annotation is used on a class, the class becomes a single-action controller. Such as:
Import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @ Controller @ RequestMapping ("/ hello") publicclassSingleActionController {@ RequestMapping (method = RequestMethod.GET) publicString sayHello () {return "hello";}}
When the @ RequestMapping annotation is used on a method, a multi-action controller can be generated. Such as:
Import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @ Controller publicclassUserController {@ RequestMapping ("/ listUsers") publicString listUsers () {return "ListUsers";} @ RequestMapping ("/ saveUser") publicString saveUser () {return "EditUser";} @ RequestMapping ("/ deleteUser") publicString deleteUser () {return "DeleteUser";}}
The @ RequestMapping annotation can also be used to specify multiple URL schemas and process them in a single way.
This is all the content of the article "how Spring MVC specifies URL mapping for processors". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!