Has problems after @PathVariable parameter value containing the '/' character,with Spring MVC

后端 未结 2 1276
广开言路
广开言路 2020-12-22 10:18

I have a use case. Spring MVC REST Url receive content using the GET method code is as follows:

@RequestMapping(\"/q/{key}\")
public String query(@PathVariab         


        
相关标签:
2条回答
  • 2020-12-22 10:35

    Annotations of @ PathVariable may not be able to solve this problem.Last use the workaround is resolved.Code is as follows:

    @RequestMapping("/q/**")
    
    0 讨论(0)
  • 2020-12-22 10:44

    You can include regular expressions in your path variable as such:

    @RequestMapping("/q/{key:.*}")
    

    This will grab EVERYTHING after the /q/. Or you can make it a more specific regex to match the pattern you are actually expecting.

    0 讨论(0)
提交回复
热议问题