@Controller annotations and controller classes in Spring MVC
When I am using Spring 3.x When using annotations, I am having a hard time knowing what type of controller class we are going to use with this @Controller Regarding
They implement the controller class
AbstractController
AbstractUrlViewController
MultiActionController
ParameterizableViewController
ServletForwardingController
ServletWrappingController
UrlFilenameViewController
AbstractWizardFormController
SimpleFormController
However, when we use the @Controller annotation in our Spring MVC program, how do we know that our @Controller annotation is implemented by any of these controllers, kindly explain to me everything
source to share
I think you are missing the point here. In the old days, in order to register a controller, your class had to have a controller interface and select a request mapping type. Sometimes you had to execute a lot of code to achieve one-time query matching.
Currently, when we have annotations, the model has changed. We can handle multiple types of requests for each controller class. Because in a single @Controller
annotated class, we can handle many query mappings.
Controller annotations are a specialized @Component
one that tells Spring that it will find handlers inside it @RequestMapping
. These handlers can be used to return Json, HTML, or to upload files.
Now the logic related to the same module can be placed under one controller class, you are more flexible about what you want to achieve. Second, @Controller
it can significantly reduce the level of code.
source to share
You are not using any of these classes. You are confusing interface Controller
with annotation.
Annotation is just a token that indicates that your bean is a Spring controller and can send HTTP receive requests. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Controller.html
The interface Controller
was introduced when there were no annotations in the Java language.
source to share
What type of controller class will we retrieve using this @Controller?
The annotation @Controller
is to tell the web container that this is a controller class for requests with URLs specified in @RequestMapping(URI)
. you won't get any class if you annotate your class with @Controller
, you just need to provide a request handler method in the class and annotate it with @RequestMapping
, although the controller class can also be annotated with @RequestMapping
in which case only the method inside the class will work as the handler method requests.
how do I know if the @@ Controller annotation implements any of these controllers?
The class names you mentioned implement the Controller
interface, not that the @Controller
annotation implements anything. These controller classes are for specific purposes, as their names indicate.
source to share