Advanced Java Session 5 (Spring MVC)

Spring MVC


What is spring mvc ?

1.Spring mvc is a model view controller design pattern which contains a library within the Spring framework that simplifies handling HTTP requests and responses.

2.Model contails data, view contains ui (html, jsp etc) files, controller is a class which controls and redirect requests.

 

 

why we use spring mvc ?

  • Separate roles - The Spring MVC separates each role, where the model object, controller, command object, view resolver, DispatcherServlet, validator, etc. can be fulfilled by a specialized object.
  • Powerful Configuration - It provides a robust configuration for both framework and application classes that includes easy referencing across contexts, such as from web controllers to business objects and validators.
  • Rapid development - The Spring MVC facilitates fast and parallel development.
  • Reusable business code - Instead of creating new objects, it allows us to use the existing business objects.
  • Easy to test - In Spring, generally we create JavaBeans classes that enable you to inject test data using the setter methods.
  • Flexible Mapping - It provides the specific annotations that easily redirect the page.


Steps to create Spring MVC Application in STS or Eclipse

Step 1: Create New Spring Project from the menu.

Click on file – new – select spring project or spring legacy project.



 

 

Step 2:

In the new project window, give the name as “spring-mvc-jdbc2” and chose template as “Spring MVC Project”. If you are using this template for the first time, STS will download it from SpringSource website. If you want, you can add the project to any working set.

 

Step 3: When the template is downloaded, in the next screen you need to provide the top-level package name. This package will be used as the base-package for Spring components, then click on finish.



 

Step 4: Once the project is created by Spring MVC template, it will look like below image.



We can add folders and jsp etc files in webapp.

 

If your project is not compiled and you see some errors, run Maven/Update Project. Make sure to check the “Force update of Snapshots/Releases” options, refer below image.



Overall project looks just like any other maven based web application with some Spring configuration files.


Comments

Popular posts from this blog

Advanced Java Session 1 (Concept of Web Application Basics And Advantages of Spring)