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:是否必須,默認(rèn)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)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Springboot ApplicationRunner的使用解讀
這篇文章主要介紹了Springboot ApplicationRunner的使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05
Java 是如何利用接口避免函數(shù)回調(diào)的方法
本篇文章主要介紹了Java 是如何利用接口避免函數(shù)回調(diào)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02
實例講解Java的Spring框架中的AOP實現(xiàn)
這篇文章主要介紹了Java的Spring框架中的AOP實現(xiàn)實例,AOP面向切面編程其實也可以被看作是一個設(shè)計模式去規(guī)范項目的結(jié)構(gòu),需要的朋友可以參考下2016-04-04
Java?設(shè)計模式以虹貓藍(lán)兔的故事講解單例模式
單例模式(Singleton?Pattern)是?Java?中最簡單的設(shè)計模式之一。這種類型的設(shè)計模式屬于創(chuàng)建型模式,它提供了一種創(chuàng)建對象的最佳方式2022-03-03
Feign如何使用protobuf的類作為參數(shù)調(diào)用
這篇文章主要介紹了Feign如何使用protobuf的類作為參數(shù)調(diào)用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03

