Regex in spring controller

后端 未结 2 1985
误落风尘
误落风尘 2020-12-09 08:53

I am trying to build a request filter that will only get used if it matches a pattern of the letter e, then a number. However I cannot seem to get it to work. I keep gettin

相关标签:
2条回答
  • 2020-12-09 09:08

    You should use:

     @RequestMapping("/e{number:\\d+})
    

    Notice the "escaped slash" before the \d digit specifier.

    0 讨论(0)
  • 2020-12-09 09:15

    According to the documentation, you have to use something like {varName:regex}. There's even an example :

    @RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}")
      public void handle(@PathVariable String version, @PathVariable String extension) {
        // ...
      }
    }
    
    0 讨论(0)
提交回复
热议问题