[英]Can I use path variable in spring controller class?
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 class?
我们可以用同样的方式将它用于全班吗?
Eg: 例如:
@Controller
@RequestMapping(value = "{version}/test")
class TestController {
}
Can we use like this? 我们可以这样使用吗? If yes how do we read
{version}
variable? 如果是,我们如何阅读
{version}
变量? Actually i need this kind of approach, based on the version i'll respond. 实际上我需要这种方法,基于我会回应的版本。 If the above approach is not possible can you please suggest me a design to solve this problem?
如果上述方法无法实现,请您建议我设计一下来解决这个问题吗?
Yes you can. 是的你可以。 Just declare it as @PathVariable in your methods if you want to access it there.
如果要在那里访问它,只需在方法中将其声明为@PathVariable即可。
@Controller
@RequestMapping(value = "{version}/test")
class TestController {
@RequestMapping(value="/something")
public ModelAndView doSomething(@PathVariable String version) {
// do something here with the version
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.