如果想让指定的属性在 Knife4j 文档中不显示为参数,可以通过使用 @Schema(hidden = true) 注解来隐藏该字段。

这样在生成的 API 文档中,这个字段将不会显示为参数。

示例如下:

import io.swagger.v3.oas.annotations.media.Schema;

public class WorkQueryVo {

    @Schema(description = "模糊查询参数")
    private String query;

    @Schema(hidden = true) // 隐藏 userId 属性
    private Long userId;

    @Schema(description = "作者id")
    private Long authorId;

    @Schema(description = "排序键")
    private String orderBy;

    @Schema(description = "排序方式(1升序,2降序,默认降序)")
    private OrderType orderType;

    // Getters and setters
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

Knife4j指定属性不显示在文档上_API

解释

  • @Schema(hidden = true): 通过这个注解,可以隐藏 userId 属性,使其不在 API 文档中显示。