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:


Instead of the preceding parameter, matrix variables understand this:


They also allow each parameter to be a list:


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 Mastering Spring MVC 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.