today I am studying the Spring MVC showcase dowlodable from the STS dashboard
I have some doubt about the new annotation @MatrixVariable introduced by Spring 3.2 version and the use of the Matrix variables in the URI path.
Within my home.jsp view I have the following link:
<a id="matrixVar" class="textLink" href="<c:url value="/data/matrixvars;foo=bar/simple" />">Matrix variable</a>
Reading here the official documentation about @MatrixVariable annotation: http://static.springsource.org/spring-framework/docs/3.2.0.M2/reference/html/mvc.html#mvc-ann-matrix-variables
I have understand the following thing:
1) Matrix variables are a couple 2) I can put these variable in any URI path segment
So I have some doubts about the previous link:
What is the URI called when I click on the previus link?
Is it /spring-mvc-showcase/data/matrixvars/simple ?!?! (with spring-mvc-showcase that is only the application name)
It would have been indifferent if I had put the "foo" matrix variable in some other position?
For example if I put the "foo" variabile in this way:
"/data;foo=bar/matrixvars/simple"
or in this way:
"/data/matrixvars/simple;foo=bar"
Has it the same meaning?
Ok, now this is the controller method that handles the HTTP Request generated by clicking the link:
@RequestMapping(value="{path}/simple", method=RequestMethod.GET)
public @ResponseBody String withMatrixVariable(@PathVariable String path, @MatrixVariable String foo) {
return "Obtained matrix variable 'foo=" + foo + "' from path segment '" + path + "'";
}
This method use the URI Template pattern to accede to a specific position of the URI.
So if my URI is data/matrixvars/simple and because my entire class is annoted by @RequestMapping("/data") annotation and my controller method is annoted by: @RequestMapping(value="{path}/simple", method=RequestMethod.GET) that means the following thing?
the path URI Template variable is related to the second URI position (that in the current URI is matrixvars) and so this method can handle also URI like:
/spring-mvc-showcase/data/SOMETHING/simple
Is it right?
Thank you very much
Andrea
Answers:
What is the URI called when I click on the [ /data/matrixvars;foo=bar/simple
] link?
/data/matrixvars/simple
; the actual matrix variables "disappear" from the URI since matrix variables are considered optional components of the URI.It would have been indifferent if I had put the "foo" matrix variable in some other position?
... so this method can handle also URI like /spring-mvc-showcase/data/SOMETHING/simple
foo
MatrixVariable as defined supporting something like /spring-mvc-showcase/data/SOMETHING;foo=bar/simple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With