Merge pull request #4064 from fscorro/BAEL-1685

Spring MVC @PathVariable dot (.) get truncated
This commit is contained in:
Loredana Crusoveanu 2018-04-25 17:56:49 +03:00 committed by GitHub
commit 5f5d83472f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package com.baeldung.spring.web.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@Configuration
public class CustomWebMvcConfigurationSupport extends WebMvcConfigurationSupport {
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();
handlerMapping.setUseSuffixPatternMatch(false);
return handlerMapping;
}
}

View File

@ -0,0 +1,30 @@
package com.baeldung.web.controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@RequestMapping("/site")
public class SiteController {
@RequestMapping(value = "/{firstValue}/{secondValue}", method = RequestMethod.GET)
public String requestWithError(@PathVariable("firstValue") String firstValue,
@PathVariable("secondValue") String secondValue) {
return firstValue + " - " + secondValue;
}
@RequestMapping(value = "/{firstValue}/{secondValue:.+}", method = RequestMethod.GET)
public String requestWithRegex(@PathVariable("firstValue") String firstValue,
@PathVariable("secondValue") String secondValue) {
return firstValue + " - " + secondValue;
}
@RequestMapping(value = "/{firstValue}/{secondValue}/", method = RequestMethod.GET)
public String requestWithSlash(@PathVariable("firstValue") String firstValue,
@PathVariable("secondValue") String secondValue) {
return firstValue + " - " + secondValue;
}
}