我在其余 Controller 中有两个 get 映射,一个具有必需的请求参数(项目 ID),一个没有具有相同路径的请求参数。
此外,在项目中设置一个带有 UI 的基本 Swagger。一开始我前面描述的2个get映射随机缺失了一个,然后我用swagger注释正确地注释了它们,但现在不带参数的get不断缺失。
@ApiOperation("Get item with the given ID")
@GetMapping(value="/resource/item", params = "id")
public Item getOne(@ApiParam(value = "the ID of the item want to view") @RequestParam(name = "id") Long id) {
//things...
}
@ApiOperation("Get all item")
@GetMapping(value="/resource/item")
public List<Item> getAll() {
//things...
}
有没有办法强制swagger同时映射get映射?
更新: 是的,路径变量可能是一个很好的解决方案,但由于遗留原因我不能这样做。
最佳答案
我会使用 Pathvariable 而不是 RequestParam
@ApiOperation("Get item with the given ID")
@GetMapping(value="/resource/item/{id}")
public Item getOne(@ApiParam(value = "the ID of the item want to view") @PathVariable Long id) {
//things...
}
这样,您的映射就会不同,并且很可能会以大方的方式显示。
关于java - Swagger 文档中缺少参数端点的 Spring boot GET 和 GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55395131/