0% found this document useful (0 votes)
3 views

Spring MVC

Uploaded by

mullaabuzar61
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Spring MVC

Uploaded by

mullaabuzar61
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Spring MVC

1. Spring MVC it is framework which is used to build web applications


2. Spring MVC has been built at the top of servlet
3. Spring MVC implements basic features of Spring core like IOC container and Dependency
injection
4. Spring MVC provides an architecture which will be controlled by FrontController
MVC design pattern:
1. Model: Models contains data of the application
2. Controller: it will be containing a business logic. And it can be created with @Controller
annotation
3. View: View is used to display the data on the browser using particular formats like JSP,
HTML, etc.
4. FrontController: in spring MVC DispatcherServlet acts a FrontController and it is
responsible to manage the flow of spring MVC architecture. DispatcherServlet handles
HTTP requests and Responses

Advantages of MVC
1. It provides separate models or roles
2. Which helps in code reusability which is easy to test. Which helps in rapid development
of application
DispatcherServlet
Steps to create maven project for spring mvc
1. Create a maven project with archetype webapp
2. Add spring web mvc and servlet dependencies
3. Create a configuration class
4. Create initializer class
5. Create controller class and design Api’s in it

Another way of creating maven project


1. Go to start.spring.io (spring initializer)
2. Select project as maven
3. Select spring boot version and language
4. And provide project metadata
5. Select packaging type as jar and java version as 17
6. Add spring web dependency
7. Add spring devtools dependency(optional)
8. And generate and extract project
9. import it and add embed jasper dependency from mvnreposetry

passing data from Controller to jsp and print it on the browser


we can pass the data from controller to view by following ways
1. using ModelAndView
1. ModelAndView is an class we can create object of this class by using ModelAndView()
constructor which accepts viewname
2. And Use addObject(“key”, value(object))
3. Return this ModelAndView object

2. Using Model Interface


1. Model is an interface using which we can send data from controller to the view and print it
2. When the request comes to the particular api internally object of Model will be created and we use
addAttribute(“key”,object(value)) to set the data to the model
3. And then this data along with the model will be pass to the mention jsp page

You might also like