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:
Open the
ProductRepository
interface and add one more method declaration,getProductsByFilter
, on it:Set<Product> getProductsByFilter(Map<String, List<String>> filterParams);
Open the implementation class,
InMemoryProductRepository
, and add the following method implementation forgetProductsByFilter
:public Set<Product> getProductsByFilter(Map<String, List<...