URL mapping with matrix variables

We are now aware of what our user is interested in. It would be a good idea to improve our Tweet controller so that it allows searching from a list of keywords.

One interesting way to pass key-value pairs in a URL is to use a matrix variable. It is pretty similar to request parameters. Consider the following code:

someUrl/param?var1=value1&var2=value2

Instead of the preceding parameter, matrix variables understand this:

someUrl/param;var1=value1;var2=value2

They also allow each parameter to be a list:

someUrl/param;var1=value1,value2;var2=value3,value4

A matrix variable can be mapped to different object types inside a controller:

  • Map<String, List<?>>: This handles multiple variables and multiple values
  • Map<String, ?>

Get Spring MVC: Designing Real-World Web Applications 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.