From 34c18aefc4a480e361138a761f27f1838d3a5df6 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 5 May 2020 22:21:38 +0200 Subject: [PATCH] JAVA-1529: Spring MVC @PathVariable with a dot (.) gets truncated --- spring-mvc-java-2/README.md | 1 + .../CustomWebMvcConfigurationSupport.java | 2 +- .../com/baeldung/pathvariable}/SiteController.java | 12 +++++++----- spring-mvc-java/README.md | 1 - 4 files changed, 9 insertions(+), 7 deletions(-) rename {spring-mvc-java/src/main/java/com/baeldung/spring/web/config => spring-mvc-java-2/src/main/java/com/baeldung/pathvariable}/CustomWebMvcConfigurationSupport.java (93%) rename {spring-mvc-java/src/main/java/com/baeldung/web/controller => spring-mvc-java-2/src/main/java/com/baeldung/pathvariable}/SiteController.java (69%) diff --git a/spring-mvc-java-2/README.md b/spring-mvc-java-2/README.md index 04c0fc958a..50cdafe1d7 100644 --- a/spring-mvc-java-2/README.md +++ b/spring-mvc-java-2/README.md @@ -2,3 +2,4 @@ - [Cache Headers in Spring MVC](https://www.baeldung.com/spring-mvc-cache-headers) - [Working with Date Parameters in Spring](https://www.baeldung.com/spring-date-parameters) +- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot) \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/CustomWebMvcConfigurationSupport.java b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/CustomWebMvcConfigurationSupport.java similarity index 93% rename from spring-mvc-java/src/main/java/com/baeldung/spring/web/config/CustomWebMvcConfigurationSupport.java rename to spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/CustomWebMvcConfigurationSupport.java index a0dd7358d0..12c208c623 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/CustomWebMvcConfigurationSupport.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/CustomWebMvcConfigurationSupport.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.web.config; +package com.baeldung.pathvariable; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/SiteController.java b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/SiteController.java similarity index 69% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/SiteController.java rename to spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/SiteController.java index 3867380665..0ba6d12a0f 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/web/controller/SiteController.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/SiteController.java @@ -1,27 +1,29 @@ -package com.baeldung.web.controller; +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; -import org.springframework.web.bind.annotation.RequestMethod; +@Controller @RequestMapping("/site") public class SiteController { - @RequestMapping(value = "/{firstValue}/{secondValue}", method = RequestMethod.GET) + @GetMapping("/{firstValue}/{secondValue}") public String requestWithError(@PathVariable("firstValue") String firstValue, @PathVariable("secondValue") String secondValue) { return firstValue + " - " + secondValue; } - @RequestMapping(value = "/{firstValue}/{secondValue:.+}", method = RequestMethod.GET) + @GetMapping("/{firstValue}/{secondValue:.+}") public String requestWithRegex(@PathVariable("firstValue") String firstValue, @PathVariable("secondValue") String secondValue) { return firstValue + " - " + secondValue; } - @RequestMapping(value = "/{firstValue}/{secondValue}/", method = RequestMethod.GET) + @GetMapping("/{firstValue}/{secondValue}/") public String requestWithSlash(@PathVariable("firstValue") String firstValue, @PathVariable("secondValue") String secondValue) { diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 0cac937a81..0edc73e0e0 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -13,6 +13,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Introduction to HtmlUnit](https://www.baeldung.com/htmlunit) - [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) - [web.xml vs Initializer with Spring](https://www.baeldung.com/spring-xml-vs-java-config) -- [Spring MVC @PathVariable with a dot (.) gets truncated](https://www.baeldung.com/spring-mvc-pathvariable-dot) - [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml) - [Accessing Spring MVC Model Objects in JavaScript](https://www.baeldung.com/spring-mvc-model-objects-js)