Jump into Spring MVC
There’s no better way to fully understand Spring MVC than to dive right in and build an appli-
cation with it. We’ll skip over the typical “Hello, world!” demo and instead build something a bit
more substantial. For the rest of the chapter, we will build a simple web application for an air-
line travel site. This application will allow us to highlight some of the most important aspects
about Spring MVC so that you can get a cohesive picture of typical system configuration and
execution.
Use Cases
Our airline travel site will begin with two simple use cases. We will use the customer’s require-
ments to help drive the design of both the service layer and the web layer. As we design and
build this system, we are keeping a close eye on where we place our business logic. We wish to
keep the web layer free of any business logic, instead focusing on web navigation and provid-
ing the glue between the service layer and the user experience.
Initially, we will cover the following two use cases for our demo application.
1.A list of current special deals must appear on the home page. Each special deal must
display the departure city, the arrival city, and the cost. These special deals are set up
by the marketing department and change during the day, so it can’t be static. Special
deals are only good for a limited amount of time.
2.A user may search for flights, given a departure city and time and an arrival city. The
results must display the departure city, the arrival city, the total cost, and how many
legs the flight will have.
Certainly these initial use cases do not warrant a complicated work flow or user experi-
ence. Use case #1 is a read-only page with dynamic content. The second use case will manifest
itself as a typical form submission with the resulting page full of dynamic content. For more
complicated work flows, such as multipage flows, you should consider using Spring Web Flow,
as it can handle complex page flows more elegantly than straight Spring MVC.
41
CHAPTER 4
■ ■ ■