Skip to content

Commit 0c81d77

Browse files
committed
Spring MVC @PathVariable dot (.) get truncated
1 parent 57a4f16 commit 0c81d77

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.spring.web.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
6+
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
7+
8+
@Configuration
9+
public class CustomWebMvcConfigurationSupport extends WebMvcConfigurationSupport {
10+
11+
@Bean
12+
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
13+
RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();
14+
handlerMapping.setUseSuffixPatternMatch(false);
15+
return handlerMapping;
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.web.controller;
2+
3+
import org.springframework.web.bind.annotation.PathVariable;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
7+
@RequestMapping("/site")
8+
public class SiteController {
9+
10+
@RequestMapping(value = "/{firstValue}/{secondValue}", method = RequestMethod.GET)
11+
public String requestWithError(@PathVariable("firstValue") String firstValue,
12+
@PathVariable("secondValue") String secondValue) {
13+
14+
return firstValue + " - " + secondValue;
15+
}
16+
17+
@RequestMapping(value = "/{firstValue}/{secondValue:.+}", method = RequestMethod.GET)
18+
public String requestWithRegex(@PathVariable("firstValue") String firstValue,
19+
@PathVariable("secondValue") String secondValue) {
20+
21+
return firstValue + " - " + secondValue;
22+
}
23+
24+
@RequestMapping(value = "/{firstValue}/{secondValue}/", method = RequestMethod.GET)
25+
public String requestWithSlash(@PathVariable("firstValue") String firstValue,
26+
@PathVariable("secondValue") String secondValue) {
27+
28+
return firstValue + " - " + secondValue;
29+
}
30+
}

0 commit comments

Comments
 (0)