我可以在spring控制器类中使用路径变量吗?
我可以在弹簧控制器类中使用路径变量吗?
我知道我们可以在控制器的方法中使用路径变量。 我们可以用同样的方式将它用于全class吗?
例如:
@Controller @RequestMapping(value = "{version}/test") class TestController { }
我们可以这样使用吗? 如果是,我们如何阅读{version}
变量? 实际上我需要这种方法,基于我会回应的版本。 如果不能采用上述方法,请您建议我设计一下来解决这个问题吗?
是的你可以。 如果要在那里访问它,只需在方法中将其声明为@PathVariable即可。
@Controller @RequestMapping(value = "{version}/test") class TestController { @RequestMapping(value="/something") public ModelAndView doSomething(@PathVariable String version) { // do something here with the version } }