【发布时间】:2020-11-07 11:31:18
【问题描述】:
我有以下几点:
@Value("${apiVersion")
private String apiVersion;
@RequestMapping(value = "/{apiVersion}/service/call", method = RequestMethod.POST)
我希望 URL 是:
/apiVersion/service/call
但事实证明{foo} 接受任何值,它实际上并不使用字符串。
有没有办法让我使用字符串值作为 URL 的一部分?
编辑
问题是我有多个电话表明我们重视这一点。
@RequestMapping(value = apiVersion + "/call1", method = RequestMethod.POST)
@RequestMapping(value = apiVersion + "/call2", method = RequestMethod.POST)
@RequestMapping(value = apiVersion + "/call3", method = RequestMethod.POST)
etc.
从技术上讲,我可以按照您的建议为每个常量声明常量,但这听起来并不理想。如果没有办法,那也没关系,我只是想知道有没有。
解决方案
向控制器添加通用映射。
@RequestMapping("${apiVersion}")
【问题讨论】:
标签: java spring spring-boot api request-mapping