Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Controller annotation and Controller Classes in Spring MVC

When I am using Spring 3.x While using annotations its difficult for me to know Which type of Controller class we are going to fetch using this @Controller With reference to

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/mvc/Controller.html

These are implementing Controller class

AbstractController
AbstractUrlViewController
MultiActionController
ParameterizableViewController
ServletForwardingController
ServletWrappingController
UrlFilenameViewController
AbstractWizardFormController
SimpleFormController

However when we are using @Controller annotation in our Spring MVC program how to know that Our @Controller annotation is implementing any of these controllers, Kindly anyone explain me

like image 236
MS Ibrahim Avatar asked Jul 28 '26 19:07

MS Ibrahim


1 Answers

I think you are missing the point here. In the old times to register a controller, your class must have implemented controller interface and choose request mapping type. Sometimes you had to implement lots of code to achieve single request mapping.

Nowadays, when we have annotations, the model has changed. We can handle multiple request types per controller class. Because in single @Controller annotated class we can handle many request mappings.

Controller annotation is a specialized @Component, that tells Spring that inside it will find @RequestMapping handlers. Those handlers can be used either for returning Json, HTML or for uploading files.

Now logic connected with same module can be placed under single controller class, you are more flexible in what you want to achieve. Secondly @Controller enables us to reduce code anount significantly.

like image 91
Beri Avatar answered Jul 30 '26 08:07

Beri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!