Home > Java > javaTutorial > How to Prevent PathVariable Truncation in Spring MVC?

How to Prevent PathVariable Truncation in Spring MVC?

Patricia Arquette
Release: 2024-10-31 03:56:02
Original
901 people have browsed it

How to Prevent PathVariable Truncation in Spring MVC?

Resolving PathVariable Truncation in Spring MVC

In your Spring MVC controller, you've encountered an issue where path variables with special characters are getting truncated. This is evident when attempting to access a URL like "/get/blah2010.08.19-02:25:47", resulting in the path variable "blahName" being shortened to "blah2010.08".

To prevent this truncation and ensure that the full path variable is preserved, you can employ a regular expression within the @RequestMapping argument. The modified code below demonstrates this solution:

@RequestMapping(method = RequestMethod.GET, value = Routes.BLAH_GET + "/{blahName:.+}")
Copy after login

By using ". ", the regular expression matches any character sequence of one or more characters. This ensures that path variables of any length and containing special characters are accepted without truncation.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template