Spring MVC @PathVariable dot (.) get truncated

This commit is contained in:
Felipe Santiago Corro 2018-04-22 19:31:27 -03:00
parent 57a4f160aa
commit 0c81d77e1b
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;
}
}