To import java package into a class, we need to use java import keyword which is used to access package and its classes into the java program. Use import to access built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name. So using the above example import com.fasterxml.jackson.annotation.JsonProperty, that line imports the JsonProperty annotation from the jackson library.
2 Why use @JsonProperty before declaring each variable?
@JsonProperty
The @JsonProperty annotation is used to map property names with JSON keys during serialization and deserialization. By default, if you try to serialize a POJO, the generated JSON will have keys mapped to the fields of the POJO. If you want to override this behavior, you can use the @JsonProperty annotation on the fields. It takes a String attribute that specifies the name that should be mapped to the field during serialization.
The above is a setter method called narrated with type LedgerAccountRequestDto. It's just the same as having a similar example with the type String. In the code above, the method returns the class instance as the return type.
Swagger is the standard way of documenting the Standard APIs. Swagger is helpful when deploying APIs in azure. Swagger is primarily used for documenting API. for the other developers to be able to use the API, the API must be properly documented; otherwise, how would they know that what are the endpoints exposed by the api and what are the operations supported on those endpoints? What parameters should they pass, and what will they get back? What authentication methods to use?. To answer these questions, it is very important to document the APIs; if you want APIs to be consumed and properly used. To learn more about Swagger, check Swagger - Javatpoint and Swagger - Github repo
@ApiModel - Provides additional information about Swagger models. Swagger-core builds the model definitions based on the references to them throughout the API introspection. The @ApiModel allows you to manipulate the metadata of a model from a simple description or name change to a definition of polymorphism.
@Valid and @Validated Annotations - In Spring, we use JSR-303's @Valid annotation for method level validation. We also use it to mark a member attribute for validation. However, this annotation doesn't support group validation.
Groups help to limit the constraints applied during validation. One particular use case is UI wizards. In the first step, we may have a certain sub-group of fields. In the subsequent step, there may be another group belonging to the same bean. So we need to apply constraints on these limited fields in each step, but @Valid doesn't support this.
In this case, for group-level, we have to use Spring's @Validated, which is a variant of JSR-303's @Valid. This is used at the method level. For marking member attributes, we continue to use the @Valid annotation.
5 What is the use of:
@ApiModelProperty(required = true, value = "")
@NotNull
@ApiModelProperty - In Swagger, this Adds and manipulates data of a model property. The @ApiModelProperty allows controlling Swagger-specific definitions such as allowed values, and additional notes. It also offers additional filtering properties in case you want to hide the property in certain scenarios.
The required parameter specifies if the parameter is required or not. The value parameter defines a brief description of this property.
The @NonNull is a common Spring annotation to declare that annotated elements cannot be null. It denotes that a parameter, field, or method return value can never be null. This is a marker annotation and it has no specific attributes.
6 What is hashCode() method actually doing?
public int hashCode() {
return Objects.hash(name, number, typeId, taxRateId);
}
You have to learn Java if you don't have the basics, researching this way will be so difficult. Check the below resource links to learn Java and Spring boot.
发布评论
评论(1)
步骤
1。这些
imports
?我将尝试使此非常简单,并将您带入 包装及其类中的Java程序。使用导入将内置和用户定义的软件包访问到Java源文件中,以便您的类可以通过直接使用其名称来参考另一个软件包中的类。因此,使用上面的示例
import com.fasterxml.jackson.annotation.jsonproperty
,该行导入JSONPROPERTY
从Jackson库注释。2为什么在声明每个变量之前使用
@jsonproperty
?@jsonproperty注释用于在序列化和避免时用JSON键映射属性名称。默认情况下,如果您尝试序列化pojo,则生成的JSON将有映射到Pojo字段的键。如果要覆盖此行为,则可以在字段上使用@jsonproperty注释。它采用一个字符串属性,该属性指定了在序列化过程中应映射到字段的名称。
3为什么我们在方法中使用类名称?例如:
上面是
setter
方法,称<代码>叙述ledgeraccountrequestdto
。它与类型字符串的类似示例相同。在上面的代码中,该方法将类实例返回为返回类型。4什么用:
@apimodel
是Swagger
注释。@apimodel
- 提供有关Swagger模型的其他信息。 Swagger-core在整个API内省中根据对它们的引用来构建模型定义。 @apimodel允许您从简单的描述或名称更改为多态性的定义来操纵模型的元数据。@valid
和@Validated
注释 - 在春季,我们使用JSR -303的@Valid
andotation 用方法级验证。我们还使用它来标记成员属性进行验证。但是,此注释不支持组验证
。@Validated
,它是JSR-303的@Valid
的变体。这是在方法级别使用的。对于标记成员属性,我们继续使用@Valid
注释。5什么用:
@apimodelproperty
- 在Swagger中,这增加并操纵了模型属性的数据。 @apimodelproperty允许控制特定于特定于允许的值和其他注释。如果您想在某些情况下隐藏该属性,它还提供其他过滤属性。必需
参数指定是否需要参数。value
参数定义了此属性的简要说明。@nonnull
是一个常见的弹簧注释,以声明注释元素不能为空。它表示参数,字段或方法返回值永远不会为null。这是标记注释,它没有特定的属性。6什么是
HashCode()
方法实际在做什么?HashCode方法是一种内置方法,它返回输入值的整数哈希值。要正确理解
hashcode()
和equals()
使用示例,请查看和 hashcode()> hashcode() java方法“ rel =“ nofollow noreferrer”> java中的hashcode方法是什么? - 教育建议,
如果您没有基础知识,则必须学习Java,这是如此困难。检查以下资源链接以学习Java和Spring Boot。
学习java
学习春季启动
I will try to make this very simple and take you step by step
1. What are these
imports
for?:To import java package into a class, we need to use java import keyword which is used to access package and its classes into the java program. Use import to access built-in and user-defined packages into your java source file so that your class can refer to a class that is in another package by directly using its name. So using the above example
import com.fasterxml.jackson.annotation.JsonProperty
, that line imports theJsonProperty
annotation from the jackson library.2 Why use
@JsonProperty
before declaring each variable?The @JsonProperty annotation is used to map property names with JSON keys during serialization and deserialization. By default, if you try to serialize a POJO, the generated JSON will have keys mapped to the fields of the POJO. If you want to override this behavior, you can use the @JsonProperty annotation on the fields. It takes a String attribute that specifies the name that should be mapped to the field during serialization.
3 Why we use class names in methods? such as:
The above is a
setter
method callednarrated
with typeLedgerAccountRequestDto
. It's just the same as having a similar example with the type String. In the code above, the method returns the class instance as the return type.4 What is the use of:
@ApiModel
is aSwagger
annotation.@ApiModel
- Provides additional information about Swagger models. Swagger-core builds the model definitions based on the references to them throughout the API introspection. The @ApiModel allows you to manipulate the metadata of a model from a simple description or name change to a definition of polymorphism.@Valid
and@Validated
Annotations - In Spring, we use JSR-303's@Valid
annotation for method level validation. We also use it to mark a member attribute for validation. However, this annotation doesn't supportgroup validation
.@Validated
, which is a variant ofJSR-303's @Valid
. This is used at the method level. For marking member attributes, we continue to use the@Valid
annotation.5 What is the use of:
@ApiModelProperty
- In Swagger, this Adds and manipulates data of a model property. The @ApiModelProperty allows controlling Swagger-specific definitions such as allowed values, and additional notes. It also offers additional filtering properties in case you want to hide the property in certain scenarios.required
parameter specifies if the parameter is required or not. Thevalue
parameter defines a brief description of this property.@NonNull
is a common Spring annotation to declare that annotated elements cannot be null. It denotes that a parameter, field, or method return value can never be null. This is a marker annotation and it has no specific attributes.6 What is
hashCode()
method actually doing?The hashCode method is an inbuilt method that returns the integer hashed value of the input value. To properly understand
hashCode()
andequals()
using examples, check out HashCode() in Java - scaler.com and also What is the hashCode method in Java? - educative.ioADVICE
You have to learn Java if you don't have the basics, researching this way will be so difficult. Check the below resource links to learn Java and Spring boot.
Learn Java
Learn Spring Boot