General overview of Model View Controller design pattern for software architecture. Gives simple examples and also more complex examples using Spring MVC framework.
Emily BaumanSoftware Development Intern at Incessant Technologies em Incessant Technologies
4. Model
● Responsible for maintaining data
● Represents knowledge - can be a single
object or a structure of objects
5. View
● Responsible for displaying data to user
● Representation of the model
○ presentation filter
○ shows only chosen data to the user
6. Controller
● Controls interactions between model & view
● Link between user and system
● The “brains” of the application
● Controls data flow into the model and
updates the view when data changes
7. Simple Example
Model View Controller
HTML CSS Web Browser
● Bare text
● The content, knowledge
of a web page
● Styling
● The display of a web
page
● Brings it all together
● Displays the view with
the knowledge of the
model, allowing
interaction for the user
8. Why is it used?
● Isolates the business logic from the user
interface
● Allows the application to be skinnable
○ same data with changeable views
14. Model: ModelAndView
● Used ModelAndView object as our model
● Spring MVC object: represents a model and
view returned by a handler
● Model is a map with <K,V>
15. View: JSP
● Used JSP pages as the view
● Calls in attributes of the model
16. Controller: Spring MVC
● Defined with @Controller annotation
● @RequestMapping annotation to map URLs
to particular handler methods
17. Spring MVC Example
@RequestMapping(value = "/approvetask", method = RequestMethod.POST)
public ModelAndView approveTask() {
ModelAndView model = new ModelAndView();
model.addObject("msg", "You have approved an employee task.");
model.setViewName("mytasks");
return model;
}