@ApiModel和@ApiModelProperty使用详解

版本

  • springfox-swagger2 (version = 2.9.2)
  • swagger-bootstrap-ui (version = 1.9.6)
  • swagger-models (version =1.6.1)

@ApiModel

使用场景:在实体类上边使用,标记类时swagger的解析类

属性名称 数据类型 默认值 说明
value String 类名 为模型提供备用名称
description String " 提供详细的类描述
parent Class Void.class 为模型提供父类以允许描述继承关系
discriminator String " 支持模型继承和多态,使用鉴别器的字段的名称,可以断言需要使用哪个子类型
subTypes Class[] {} 从此模型继承的子类型数组
reference String ‘’ 指定对应类型定义和引用,覆盖指定的任何其它元数据

@ApiModelProperty

使用场景:使用在被 @ApiModel 注解的模型类的属性上

属性名称 数据类型 默认值 说明
value String " 属性简要说明
name String " 运行覆盖属性的名称,重写属性名称
allowableValues String " 限制参数可接受的值
access String " 过滤属性
notes String " 尚未使用
dataType String " 参数的数据类型
required boolean false 是否必传
position int 0 允许在模型中排序属性
hidden boolean false 隐藏模型属性
example String " 属性的示例值
readOnly boolean false 指定模型属性为只读,false:非只读
reference String " 指定对应类型定义的引用,覆盖指定的任何其他元数据
allowEmptyValue boolean false 允许传空置,false:不允许传空值

你可能感兴趣的:(Springboot)