文章目录 1.、value() 2、name() 3、allowableValues() 4、access() 5、notes() 6、dataType() 7、required() 8、 position() 9、hidden() 10、example() 11、readOnly(……
文
章
目
录
- 1.、value()
- 2、name()
- 3、allowableValues()
- 4、access()
- 5、notes()
- 6、dataType()
- 7、required()
- 8、 position()
- 9、hidden()
- 10、example()
- 11、readOnly()
- 12、reference()
- 13、allowEmptyValue()
- 示例
学过Swagger的应该都知道@ApiModelProperty是Swagger的常用注解,它的作用是添加和操作属性模块的数据,以下总结了@ApiModelProperty内部的常用属性:
1.、value()
参数类型为String,作用为此属性的简要描述。源码:
String value() default \"\";
2、name()
参数类型为String,作用为允许重写属性的名称。源码:
String name() default \"\";
3、allowableValues()
参数类型为String,作用为允许此参数存储的长度。源码:
String allowableValues() default \"\";
4、access()
参数类型为String,作用为允许从API文档中过滤属性。源码:
String access() default \"\";
5、notes()
参数类型为String,作用为该字段的注释说明。源码:
String notes() default \"\";
6、dataType()
参数类型为String,作用为参数的数据类型。源码:
String dataType() default \"\";
7、required()
参数类型为boolean,作用为指定参数是否可以为空,默认为false。源码:
boolean required() default false;
8、 position()
参数类型为int,作用为允许显式地对模型中的属性排序。源码:
int position() default 0;
9、hidden()
参数类型为boolean,作用为是否允许模型属性隐藏在Swagger模型定义中,默认为false。源码:
boolean hidden() default false;
10、example()
参数为String类型,作用为属性的示例值。源码:
String example() default \"\";
11、readOnly()
参数类型为boolean,作用为是否允许将属性指定为只读,默认为false。源码:
boolean readOnly() default false;
12、reference()
参数类型为String,作用为指定对对应类型定义的引用,重写指定的任何其他数据名称。源码:
String reference() default \"\";
13、allowEmptyValue()
参数类型为boolean,作用为是否允许传递空值,默认为false源码:
boolean allowEmptyValue() default false;
示例
@ApiModelProperty(value = \"ID主键\",name = \"id\",
allowableValues = \"20\",
access = \"1\",
notes = \"学生的id\",
dataType = \"int\",
required = false,
position = 1,
hidden = true,
example = \"1\",
readOnly = false,
reference = \"id\",
allowEmptyValue = false)
@TableId(value = \"id\",type = IdType.AUTO)
private Integer id;
以上就是Swagger @ApiModelProperty详解内容。
还没有评论呢,快来抢沙发~