SpringBoot中的@ApiModelProperty注解作用
更新時間:2022年01月10日 15:22:54 作者:象在舞
這篇文章主要介紹了SpringBoot中的@ApiModelProperty注解作用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教。
@ApiModelProperty注解作用
@ApiModelProperty()注解用于方法、字段,表示對model屬性的說明或者數(shù)據(jù)操作更改,以下是它的源碼:
// 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() default ""; 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="狀態(tài)", name="status", required=true) ? ? ? private Integer status; ? ? ? private String pwd; ? ? ? private String nName; ? ? ? private Integer flag; ? ? ? ? @ApiModelProperty(value="grade數(shù)組", hidden=true) ? ? ? private String[] grades; ? ? ? private List<String> gradeList; }
@ApiModelProperty()失效
解決方法
可以把
@ApiModelProperty(value= "id")
替換成
@ApiModelProperty(example = "id")
即可~
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Springboot ApplicationRunner的使用解讀
這篇文章主要介紹了Springboot ApplicationRunner的使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05實例講解Java的Spring框架中的AOP實現(xiàn)
這篇文章主要介紹了Java的Spring框架中的AOP實現(xiàn)實例,AOP面向切面編程其實也可以被看作是一個設計模式去規(guī)范項目的結構,需要的朋友可以參考下2016-04-04Feign如何使用protobuf的類作為參數(shù)調用
這篇文章主要介紹了Feign如何使用protobuf的類作為參數(shù)調用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03