Can I use path variable in spring controller class?

前端 未结 1 526
别跟我提以往
别跟我提以往 2020-12-09 08:26

Can I use path variable for spring controller class?

I know that we can use path variables in controller\'s methods. In the same fashion can we use it for entire cl

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

    Yes you can. Just declare it as @PathVariable in your methods if you want to access it there.

    @Controller
    @RequestMapping(value = "{version}/test")
    class TestController {
    
        @RequestMapping(value="/something")
        public ModelAndView doSomething(@PathVariable String version) {
           // do something here with the version
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题