Spring MVC Controller extends another Controller

Controller’s in the Spring MVC are mainly used for processing the requests and sending a model back to the views.
What happens when a Spring MVC controller extends another Controller.

When a Spring MVC controller extends another Controller, the functionality of the base controller can be directly used by the child controller using the request URL of the child controller.

You have a Controller that does some action

For calling the someAction() method you use the following URL


Now you have some other Controller that also need to have the same functionality as the someAction() method.
Then those controllers can extend the ParentController and then use the someAction method as follows

Since the ChildController extends the ParentController we can call the someAction() method of ParentController using the following URL. Note instead of parent in the URL we directly use the child request mapping url.


Controller extending can be useful when you have many pages that have same functionality across the pages and you need to reuse your code. This can be also achieved by adding the code in a Utility or Common class. you can use either of the 2.

Please do let me know if you need any more info in this or any articles available on this site.