Using matrix variables
In the last section, we saw the URI template facility to bind variables in the URL request path. However, there is one more way to bind variables in the request URL in a name-value pair style; these bound variables are referred to as matrix variables within Spring MVC. Look at the following URL:
http://localhost:8080/webstore/products/filter/price;low=500;high=1000
In this URL, the actual request path is just up to http://localhost:8080/webstore/products/filter/price
, after which we have something like low=500;high=1000
; here, low
and high
are just matrix variables. However, what makes matrix variables so special is the ability to assign multiple values for a single variable; this means that we can assign a list of values to a URI variable. Take a look at the following URL:
http://localhost:8080/webstore/products/filter/ByCriteria;brand=google,dell;category=tablet,laptop
In the given URL, we have two variables, namely, brand
and category
; both have multiple values...