[Spring MVC] learning notes -- @ Controller, mvc -- @ controller
Before explaining @ Controller, describe the official Spring MVC document.
Some people may be like me. When I first got started with Spring MVC, I found that the Spring MVC project could not be found on the Spring website.
This is because Spring MVC is put in Spring Framework.
You can open The reference of Spring Framework. Some of them specifically introduce Spring MVC, "V. The Web ".
Controller is C in MVC.
@ Controller is used in Spring-MVC to mark a class as controller to provide services.
@Controllerpublic class HelloWorldController { @RequestMapping("/helloWorld") public String helloWorld(Model model) { return "helloWorld"; } }
To automatically find our defined controller, you need to add a line to the xml file.
<context:component-scan base-package="xxx.xxx"/>
What is @ Controller @ RequestMapping in springmvc?
Annotation function ah, @ Controller is to register the Controller you write, @ RequestMapping is to register the path you access
In spring mvc, can methods in the Controller be called in another Controller layer?
If it is a method, I don't know if it can be called. I haven't tried it.
If it is a controller, you can certainly not directly call it, you can only jump.
If you need to remove the method, pull it out and do not put it in the Controller, because it does not conform to the MVC design philosophy.
If yes, It is not thread-safe.