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

Time for action – adding class-level request mapping


Let's add a @RequestMapping annotation on our ProductController class to demonstrate the relative request mapping feature. However, before that, we just want to ensure that you have already replaced the ProductRepository reference with the ProductService reference in the ProductController class as part of the previous chapter's Time for action – creating a service object section. Because contacting the persistence layer directly from the presentation layer is not a best practice, all access to the persistence layer should go through the service layer. Perform the following steps (those who have completed this exercise can directly start from step 5; others please continue from step 1):

  1. Create an interface called ProductService under the com.packt.webstore.service package in src/main/java and add two method declarations in it as follows:

    List<Product> getAllProducts();
    Product getProductById(String productID);
  2. Create a class called ProductServiceImpl...