Problem:
When a Spring MVC controller defines a @PathVariable with a custom path variable argument, path segments containing special characters get truncated.
Example:
@RequestMapping(method = RequestMethod.GET, value = Routes.BLAH_GET + "/{blahName}")
Passing a URI with a path variable blah2010.08.19-02:25:47 would result in the blahName parameter being truncated to blah2010.08.
Resolution:
To prevent truncation, use a regular expression in the @RequestMapping argument:
@RequestMapping(method = RequestMethod.GET, value = Routes.BLAH_GET + "/{blahName:.+}")
The . = regex allows any number of characters (including specials) after the leading dot, effectively capturing the entire path segment as the path variable value. The request.getRequestURI() will then return the complete URI, including the full blahName.
The above is the detailed content of How to Prevent @PathVariable Truncation in Spring MVC?. For more information, please follow other related articles on the PHP Chinese website!