There are situations when you want to pass a number of parameters through a bar, but the number can be variable, and values in these parameters can occur singly or as a set. Let’s take a look at the search engine on the popular Allegro portal. Let’s say we are looking for a car for ourselves. We use the search engine and choose an eg brand, model, price, engine capacity. We can focus on a specific model of a specific brand for a certain amount of money, but someone else may look for several brands of cars, without specifying the price or engine capacity for that by determining the approximate location … Now we want to implement such a search engine. Imagine this tree of forks that would have to be poked in ordinary servlets. Fortunately, Spring comes to our rescue again.

Of course, the parameters may be more or less, and we may have a different number of values in each parameter. We will start with a small modification in our configuration file **** – servlet.xml. Line:

<MVC annotation-driven />

We work on:

<mvc: annotation-driven enableMatrixVariables = “true” />

We make a counter and create a method that will map the address / filter / parameters:

Notice that @RequestMapping takes into account the path parameter enclosed in braces {filters} as in the previous chapter. We now have a new parameter for the @MatrixVariable method. This is used to receive array variables. We move like them after each map, except that each element in the map is a list (maybe a single item). Map elements are parameters, and the list elements associated with these parameters are their values.

Simple, comfortable, effective 🙂