Web development using Spring MVC
Spring MVC architecture for Java Web Development.
What is Spring MVC
Spring MVC is a Java framework for web development. It helps us to make flexible and loosely coupled web applications.MVC stands for Model, View, and Controller. The model represents our data object. The view is responsible for how our user interface should look like. The Controller is where our all business logic is implemented.
Processing request/response in Spring MVC.
When a request is made from a web browser, It first reaches the front controller(DispatcherServlet). Front Controller scans the URL and with the help of the handler mapping, it routes to the appropriate controller. The controller if required interacts with the service layer to fetch the data model. The controller then passes it to the front controller. The front controller then interacts with the view layer to resolve how our page should be displayed. The view layer sends it back to the front controller then the front controller renders it back to the browser.
Features of Spring MVC.
Separation of Concerns: Springs MVC creates a loosely coupled application where each layer has different roles.
Powerful Configuration: Spring MVC provides an annotations-based configuration that helps rapid configuration of our application.
Reusable business code: Instead of creating a new object for each request it allows us to use the existing object multiple times in our application.
Creating Spring MVC project.
Method 1: Using maven web project.
Start a maven web project then add all required dependencies in the pom.xml file. Visit mvnrepository.com and search for required dependency and add an appropriate dependency.
Now create controller, services, and model class as per your project requirements.
Method 2: Using spring boot.
This is the fastest way to start the spring MVC application. Visit the website start.spring.io and select the dependency as per project requirements. Then download the zip file and after extracting it start it in your IDE.
References: