diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/CustomWebMvcConfigurationSupport.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/CustomWebMvcConfigurationSupport.java new file mode 100644 index 0000000000..4a9f6a3431 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/CustomWebMvcConfigurationSupport.java @@ -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; + } +} diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/SiteController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/SiteController.java new file mode 100644 index 0000000000..3867380665 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/SiteController.java @@ -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; + } +}