“This is the 24th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”


Related articles

Java with Notes: Java with Notes


preface

  • We talked about that in the last video@ApiModel().
  • I bring it to you today@ApiModelProperty()Break down!
  • As the name suggests, this thing is used to annotate properties

ApiModelProperty()

  • Familiar friends know, first go in to see!
  • @Target({ElementType.METHOD, ElementType.FIELD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface ApiModelProperty {
        String value() default "";
    ​
        String name() default "";
    ​
        String allowableValues() default "";
    ​
        String access() default "";
    ​
        String notes() default "";
    ​
        String dataType() default "";
    ​
        boolean required() default false;
    ​
        int position() default 0;
    ​
        boolean hidden() default false;
    ​
        String example() default "";
    ​
        /** @deprecated */
        @Deprecated
        boolean readOnly() default false;
    ​
        ApiModelProperty.AccessMode accessMode() default ApiModelProperty.AccessMode.AUTO;
    ​
        String reference() default "";
    ​
        boolean allowEmptyValue() default false;
    ​
        Extension[] extensions() default {@Extension(
        properties = {@ExtensionProperty(
        name = "",
        value = ""
    )}
    )};
    ​
        public static enum AccessMode {
            AUTO,
            READ_ONLY,
            READ_WRITE;
    ​
            private AccessMode() {
            }
        }
    }
    Copy the code
  • by@TargetIt can be used on properties or methods.
  • by@RetentionIt takes effect at runtime.
  • So, what are all these parameters? Let’s break it down.
  • The test case

    • @ Data @ ApiModel (value = "students", the description = "this is such a detailed description of the information", the parent = CourseResponse. Class, subTypes. = CourseResponse class) Public class StudentResponse{@apiModelProperty (value = "name", name = "name", allowableValues = "32", access = "1", Notes = "user name ", dataType = "String", Required = false, position = 0, hidden = false, example =" big fish ", readOnly = false, reference = "name", allowEmptyValue = false ) private String name; @apiModelProperty (value = "age ") private int age; @apiModelProperty (value = "ApiModelProperty ") private String like; @ApiModelProperty() private CourseResponse perResponse; }Copy the code
  • Start to see results

  • The effect has already been seen. Let’s explain each of its parameters.

conclusion

  • value()

    • The argument is of type String and serves as a brief description of the property.
  • name()

    • The argument is of type String and acts as the name of the property to allow overwriting.
  • allowableValues()

    • The parameter type is String, which limits the storage length of this parameter.
  • access()

    • The parameter is of type String and is used to allow attributes to be filtered from API documents
  • notes()

    • The parameter type is String and serves as a comment for the field
  • dataType()

    • The parameter type is String and acts as the data type of the parameter.
  • required()

    • The parameter type is String. It specifies whether the parameter can be null. The default value is false
  • position()

    • The argument is of type int and is used to allow explicit sorting of attributes in the model.
  • hidden()

    • The parameter type is Boolean. Allows model attributes to be hidden in Swagger model definitions. The default value is false.
  • example()

    • The argument is of type String and acts as an example value for the property.
  • readOnly()

    • The type of the Boolean parameter is Boolean. The default value is false.
  • reference()

    • The argument is of type String and is used to specify a reference to the corresponding type definition, overriding any other data names specified.
  • allowEmptyValue()

    • The type of this parameter is Boolean. The value allows null values to be passed. The default value is false
  • Since there are too many of these parameters, and many are not commonly used, I won’t show you the difference.
  • Interested partners can try my summary ~
  • The above are all personal words, if there is any wrong, welcome to point out.
  • If it is helpful to you, I hope to like a point of concern!

The road ahead is long, I see no end, I will search high and low

If you think I bloggers write well! Writing is not easy, please like, follow, comment and give encouragement to the blogger ~ Hahah