MVC basic Flashcards

1
Q

How Spring MVC Works behind the scenes

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Components of a Spring MVC Application

A
  • A set of web pages to layout UI components

  • A collection of Spring beans (controllers, services, etc…)

  • Spring configuration (XML, Annotations or Java)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Spring MVC Front Controller

A

Spring MVC Front Controller

Front controller known as DispatcherServlet Part of the Spring Framework

Already developed by Spring Dev Team


You as a developer will create

Model objects (orange)

View templates (dark green)

Controller classes (yellow)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Spring MVC Front Controller

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Controller?

A
  • Code created by developer

  • Contains your business logic
    • Handle the request
    • Store/retrieve data (db, web service…)
    • Place data in model

  • Send to appropriate view template
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Model

A
  • Model: contains your data

  • Store/retrieve data via backend systems
    • database, web service, etc…
    • Use a Spring bean if you like

  • Place your data in the model
    • Data can be any Java object/collection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

View Template

A
  • Spring MVC is flexible
    • Supports many view templates

  • Most common is JSP + JSTL

  • Developer creates a page
    • Displays data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Spring MVC Configuration Process - Part 1

A

Add configurations to file: WEB-INF/web.xml

  • Configure Spring MVC Dispatcher Servlet

  • Set up URL mappings to Spring MVC Dispatcher Servlet
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Spring MVC Configuration Process - Part 2

A

Add configurations to file: WEB-INF/spring-mvc-demo-servlet.xml

  • Add support for Spring component scanning

  • Add support for conversion, formatting and validation

  • Configure Spring MVC View Resolve
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Spring MVC example

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Development Process

A
  1. Create Controller class

  2. Define Controller method

  3. Add Request Mapping to Controller method

  4. Return View Name

  5. Develop View Page
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Step 1: Create Controller class

A

Annotate class with @Controller

  • @Controller inherits from @Component … supports scanning

@Controller

public class HomeController { }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Step 2: Define Controller method

A
@Controller
public class HomeController {

public String showMyPage() { …

}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Step 3: Add Request Mapping to Controller method

A
@Controller
public class HomeController {

@RequestMapping(“/”) public String showMyPage() {

return “main-menu”; }

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Find View Page Magic

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Step 5: Develop View Page

A

File: /WEB-INF/view/main-menu.jsp

Spring MVC Demo - Home Page

17
Q
A
18
Q
A