Defining a controller
Controllers are presentation layer components that are responsible for responding to user actions. These actions could be entering a particular URL on the browser, clicking on a link, submitting a form on a web page, and so on. Any regular Java class can be transformed into a controller by simply being annotated with the @Controller
annotation (org.springframework.stereotype.Controller
).
And we had already learned that the @Controller
annotation supports Spring's autodetection mechanism for auto-registering the bean definition in the web application context. To enable such auto-registering, we must add the <context:component-scan>
tag in the web application context configuration file; we have seen how to do that in the The web application context configuration section of Chapter 2, Spring MVC Architecture – Architecting Your Web Store.
A controller class is made up of request-mapped methods, also called handler methods. Handler methods are annotated...