Skip to main content

Spring PathVariable with dots

Greetings!

Spring helps us in many ways. But in sometimes it do more than we want.
If we want to have dots like xx.yy.zz in our path Spring will remove last part probably thinking it as a file type.
xx.yy.zz will become xx.yy
@GetMapping(value = "/{myvar}")
public String someMethod(@PathVariable String myvar) {
    // myvar is xx.yy here    // do something with myvar    // return}

Solution:
Use regex to allow dots
@GetMapping(value = "/{myvar:.+}")
public String someMethod(@PathVariable String myvar) {
    // myvar is xx.yy.zz here    // do something with myvar    // return}

for more information check this stackoverflow answer.

Comments