Unlike the @RequestParam
the @MatrixVariable
is separated by a semicolon ;
and multiple values are separated by a comma ,
. Read its documentation:
Annotation which indicates that a method parameter should be bound to a name-value pair within a path segment. Supported for RequestMapping annotated handler methods.
There are plenty of examples and variations of the usage. Here are some exapmles:
URL: localhost:8080/person/Tom;age=25;height=175
and Controller:
@GetMapping("/person/{name}")
@ResponseBody
public String person(
@PathVariable("name") String name,
@MatrixVariable("age") int age,
@MatrixVariable("height") int height) {
// ...
}
It can be even mapped to String[]
.
URL: localhost:8080/person/Tom;languages=JAVA,JAVASCRIPT,CPP,C
and Controller
public String person(
@PathVariable("name") String name,
@MatrixVariable("languages") String[] languages) {
// ...
}