@Retention(value=RUNTIME) @Target(value=METHOD) public @interface ParamPath
A controller class's action methods can be annotated with this annotation to specify the mapping of the method's parameters to the request path. This allows for cleaner application URLs.
Parameters in the path must be prefixed with a colon. Also, there must be a
matching parameter in the method signature annotated with Param
. When
an action method is obtaining its parameters through the request path, any
matching HTTP request parameters are ignored. Therefore, matching path parameters
and request parameters cannot both be used when invoking an action method.
As an example, consider the following action method:
@Action @ParamPath("to/:name") public View sayHello(@Param("name") String name) { return new JSP("hello"); }
We can invoke this method by making the following request:
http://.../some-controller/sayHello/to/John
Path parameters can also be defined with custom regular expression definitions. Take the following action method as an example:
@Action @ParamPath("to/:name<[a-z]+>") public View sayHello(@Param("name") String name) { return new JSP("hello"); }
The value inside the angle brackets, next to ":name", is a custom regular expression definition. When no such definition exists, the regular expression [^/]+ is used by default. When a custom definition exists, it will be used to match an incoming path to the route. Thus, the following request will not match the action method above:
http://.../some-controller/sayHello/to/123
public abstract String value
Copyright © 2011-2012 MojaveMVC.org