From the course: Spring: Spring MVC

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add controllers and test the application

Add controllers and test the application

From the course: Spring: Spring MVC

Start my 1-month free trial

Add controllers and test the application

- [Instructor] Now that we have all the necessary configuration in place, let's go ahead and add a basic HomeController class. So on the IDE, right-click again on com.test, create a class, and let's say HomeController, that's the name. Now this is the first controller that we're writing as a part of the Spring MVC project. Now in order to designate this as controller, we will have to annotate it appropriately. The annotation for that is Controller. So Spring MVC will then know that this is a controller component. Now this controller component is supposed to be intercepting some HTTP request, and that request should have a unique URL pattern which is going to be unique to the HomeController. Now that URL pattern can be defined with another annotation, which is called GetMapping. So for this GetMapping, you can just specify an argument with the help of brackets, and say /home. Now for this /home pattern, we're supposed to…

Contents