SpringBoot中的@ApiModelProperty注解作用

网友投稿 1063 2022-11-09

SpringBoot中的@ApiModelProperty注解作用

SpringBoot中的@ApiModelProperty注解作用

目录@ApiModelProperty注解作用主要字段说明举个简单的例子@ApiModelProperty()失效解决方法

@ApiModelProperty注解作用

@ApiModelProperty()注解用于方法、字段,表示对model属性的说明或者数据操作更改,以下是它的源码:

// IntelliJ API Decompiler stub source generated from a class file

// Implementation of methods is not available

package io.swagger.annotations;

@java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.FIELD})

@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)

public @interface ApiModelProperty {

java.lang.String value() default "";

java.lang.String name() default "";

java.lang.String allowableValues() default "";

java.lang.String access() default "";

java.lang.String notes() dehttp://fault "";

java.lang.String dataType() default "";

boolean required() default false;

int position() default 0;

boolean hidden() default false;

java.lang.String example() default "";

/**

* @deprecated

*/

@java.lang.Deprecated

boolean readOnly() default false;

io.swagger.annotations.ApiModelProperty.AccessMode accessMode() default io.swagger.annotations.ApiModelProperty.AccessMode.AUTO;

java.lang.String reference() default "";

boolean allowEmptyValue() default false;

io.swagger.annotations.Extension[] extensions() default {@io.swagger.annotations.Extension(properties = {@io.swagger.annotations.ExtensionProperty(name = "", value = "")})};

static enum AccessMode {

AUTO, READ_ONLY, READ_WRITE;

private AccessMode() { /* compiled code */ }

}

}

主要字段说明

value:字段说明name:重写属性名字dataType:重写属性类型required:是否必须,默认falseexample:举例hidden:隐藏

举个简单的例子

@ApiModel(value="user", description="users")

public class UserVO implements Serializable{

private static final long serialVersionUID = 1L;

@ApiModelProperty(value="用户名", name="username", example="xzw")

private String username;

@ApiModelProperty(value="状态", name="status", required=true)

private Integer status;

private String pwd;

private String nName;

private Integer flag;

@ApiModelProperty(value="grade数组", hidden=true)

private String[] grades;

private List gradeList;

}

@ApiModelProperty()失效

解决方法

可以把

@ApiModelProperty(value= "id")

替换成

@ApiModelProperty(example = "id")

即可~

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:LeetCode-643. Maximum Average Subarray I
下一篇:LeetCode-891. Sum of Subsequence Widths
相关文章

 发表评论

暂时没有评论,来抢沙发吧~