JAVA-1529: Spring MVC @PathVariable with a dot (.) gets truncated

This commit is contained in:
Krzysiek
2020-05-05 22:21:38 +02:00
parent 87b4ea1d0d
commit 34c18aefc4
4 changed files with 9 additions and 7 deletions
@@ -0,0 +1,17 @@
package com.baeldung.pathvariable;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class CustomWebMvcConfigurationSupport extends WebMvcConfigurationSupport {
@Override
protected PathMatchConfigurer getPathMatchConfigurer() {
PathMatchConfigurer pathMatchConfigurer = super.getPathMatchConfigurer();
pathMatchConfigurer.setUseSuffixPatternMatch(false);
return pathMatchConfigurer;
}
}
@@ -0,0 +1,32 @@
package com.baeldung.pathvariable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/site")
public class SiteController {
@GetMapping("/{firstValue}/{secondValue}")
public String requestWithError(@PathVariable("firstValue") String firstValue,
@PathVariable("secondValue") String secondValue) {
return firstValue + " - " + secondValue;
}
@GetMapping("/{firstValue}/{secondValue:.+}")
public String requestWithRegex(@PathVariable("firstValue") String firstValue,
@PathVariable("secondValue") String secondValue) {
return firstValue + " - " + secondValue;
}
@GetMapping("/{firstValue}/{secondValue}/")
public String requestWithSlash(@PathVariable("firstValue") String firstValue,
@PathVariable("secondValue") String secondValue) {
return firstValue + " - " + secondValue;
}
}