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, ...

Get Spring MVC Beginner’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.