Home > Java > javaTutorial > body text

How to Prevent PathVariable Truncation in Spring MVC?

Patricia Arquette
Release: 2024-10-31 03:56:02
Original
802 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!