Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The persistence layer


Since we had a single product, we just instantiated it in the controller itself and displayed this product information on our web page successfully. However, a typical webstore contains thousands of products; all the information for these products is usually stored in a database. So, we need to make our ProductController class smart enough to load all the product information from the database into the model. However, if we write all the data retrieval logic in the ProductController class itself to retrieve product information from the database, our ProductController class will blow down into a big chunk of file. Logically speaking, data retrieval is not the duty of the controller because the controller is a presentation layer component. Moreover, we need to organize data retrieval code in a separate layer so that we can reuse this logic as much as possible from other controllers and layers.

How do we retrieve data from the database the Spring MVC way? There comes the...