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 – showing the products based on filter


Consider a situation where we want to filter the product list based on the brand and category variables. For example, you want to list all the products that fall under the category laptop and tablets and from the manufacturers google and dell. With the help of the matrix variables, we can form a URL to bind the brand and category variables' values into the URL as follows:

http://localhost:8080/webstore/products/filter/ByCriteria;brand=google,dell;category=tablet,laptop

Let's map this URL to a handler method with the help of the @MatrixVariable annotation:

  1. Open the ProductRepository interface and add one more method declaration, getProductsByFilter, on it:

    Set<Product> getProductsByFilter(Map<String, List<String>> filterParams);
  2. Open the implementation class, InMemoryProductRepository, and add the following method implementation for getProductsByFilter:

    public Set<Product> getProductsByFilter(Map<String, List&lt...