Skip to Main Content
Spring MVC Beginner's Guide
book

Spring MVC Beginner's Guide

by Amuthan Ganeshan
June 2014
Beginner to intermediate content levelBeginner to intermediate
304 pages
7h 25m
English
Packt Publishing
Content preview from Spring MVC Beginner's Guide

Time for action – showing products based on category

Let's add a category view to the products page using the path variable:

  1. Open the ProductRepository interface and add one more method declaration on its getProductsByCategory method:
    List<Product> getProductsByCategory(String category);
  2. Open the implementation class InMemoryProductRepository and add an implementation for the previously declared method as follows:
    public List<Product> getProductsByCategory(String category) {
      List<Product> productsByCategory = new ArrayList<Product>();
        
      for(Product product: listOfProducts) {
        if(category.equalsIgnoreCase(product.getCategory())){
          productsByCategory.add(product);
        }
      }
      
      return productsByCategory;
    }
  3. Similarly, open the ProductService interface and add one more ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Spring MVC Beginner's Guide - Second Edition

Spring MVC Beginner's Guide - Second Edition

Amuthan Ganeshan
Spring MVC: Designing Real-World Web Applications

Spring MVC: Designing Real-World Web Applications

Shameer Kunjumohamed, Hamidreza Sattari, Alex Bretet, Geoffroy Warin

Publisher Resources

ISBN: 9781783284870Supplemental Content