是这些pathParams或pathVariable

时间:2016-10-18 11:53:07

标签: java web-services rest

我必须编写API调用

@GET
@Path("/{settingName1, settingName2}")
public Response getNetworkSettingValue(@ApiParam(value = "Name") @QueryParam("name") String name,
        @ApiParam(value = "City") @QueryParam("city") String city,
        @ApiParam(value = "State") @QueryParam("state") String state) {}

这里我怀疑如何获得settingName1 & settingName2值, 可写像

@ApiParam(value = "SettingName1") @PathParam("settingName1") String settingName1

@ApiParam(value = "SettingName1") @PathVariable("settingName1") String settingName1

方法声明中的

获取这两个值的任何其他方式

2 个答案:

答案 0 :(得分:0)

通过@Path注释,我假设您正在使用JAX-RS(Jersey,RESTEasy等)。所以它应该是:

@ApiParam(value = "SettingName1") @PathParam("settingName1") String settingName1

如果你使用的是Spring,那应该是:

@ApiParam(value = "SettingName1") @PathVariable("settingName1") String settingName1

答案 1 :(得分:0)

你的注释与春天和招摇都混在一起。

如果你想用spring访问pathvariables而不是像

那样
@RequestMapping(value = "/{settingName1}/{settingName2}", method = equestMethod.GET)
public Response getNetworkSettingValue(@ApiParam(value = "settingName1") @PathVariable final String settingName1,
                                       @ApiParam(value = "settingName2") @PathVariable final String settingName2) {
...
     return new Response();
}