java - Swagger 文档中缺少参数端点的 Spring boot GET 和 GET

标签 java spring spring-boot swagger

我在其余 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/

相关文章:

java - Guice 类型文字绑定(bind)

java - 从网页启动小程序

java - org.h2.jdbc.JdbcSQL异常 : Schema "MYAPP" not found; SQL statement

Spring Boot 提供静态内容 : addResourceLocations vs static-locations

java - 在 Spring Boot 中,我有一个异步调用,我必须等待下一个线程才能等到 CRUD 操作

java - 从mongodb中提取特定字段

Java:子类化泛型类

spring - 带有旧式单点登录的Spring Security

java - IgniteCache 不调用 loadCache()

spring - 当 application.properties 中的值发生变化时,as spring 属性多久更新一次?