Swagger 没有获得 PathVariable
Swagger doesn't obtain PathVariable
我在使用 Swagger 和 Spring Boot 时遇到了问题。我有这样的方法:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(name = "Product id", value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
此操作在 Postman 中非常有效,当我在我的路径上调用 GET
方法并指定 id 时,我得到了所需的产品。但它不适用于招摇。我尝试调试,发现在此操作中调用 ID 获得 '{id}'
值,而不是产品 ID。我怎样才能解决这个问题并使 PathVariable 被正确地获取?
问题可能与 @ApiParam
name
属性有关:要么去掉它:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
或提供适当的值:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(name = "id", value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
我在使用 Swagger 和 Spring Boot 时遇到了问题。我有这样的方法:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(name = "Product id", value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
此操作在 Postman 中非常有效,当我在我的路径上调用 GET
方法并指定 id 时,我得到了所需的产品。但它不适用于招摇。我尝试调试,发现在此操作中调用 ID 获得 '{id}'
值,而不是产品 ID。我怎样才能解决这个问题并使 PathVariable 被正确地获取?
问题可能与 @ApiParam
name
属性有关:要么去掉它:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
或提供适当的值:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(name = "id", value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}