大摇摇欲坠在Java后端工作?

发布于 2025-02-05 20:37:49 字数 1457 浏览 2 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2025-02-12 20:37:49

步骤

1。这些 imports

import com.fasterxml.jackson.annotation.JsonProperty;

我将尝试使此非常简单,并将您带入 包装及其类中的Java程序。使用导入将内置和用户定义的软件包访问到Java源文件中,以便您的类可以通过直接使用其名称来参考另一个软件包中的类。因此,使用上面的示例 import com.fasterxml.jackson.annotation.jsonproperty ,该行导入 JSONPROPERTY 从Jackson库注释。

2为什么在声明每个变量之前使用 @jsonproperty

@JsonProperty

@jsonproperty注释用于在序列化和避免时用JSON键映射属性名称。默认情况下,如果您尝试序列化pojo,则生成的JSON将有映射到Pojo字段的键。如果要覆盖此行为,则可以在字段上使用@jsonproperty注释。它采用一个字符串属性,该属性指定了在序列化过程中应映射到字段的名称。

3为什么我们在方法中使用类名称?例如:

public LedgerAccountRequestDto taxRateId(String taxRateId) {
    this.taxRateId = taxRateId;
    return this;
}

上面是 setter 方法,称<代码>叙述 ledgeraccountrequestdto 。它与类型字符串的类似示例相同。在上面的代码中,该方法将类实例返回为返回类型。

4什么用:

 @ApiModel(description = "transaction request")
 @Validated**

@apimodel Swagger 注释。

Swagger 是记录标准API的标准方法。在将API部署在Azure中时,Swagger很有帮助。 Swagger主要用于记录API。为了使其他开发人员能够使用API​​,必须正确记录API;否则,他们怎么会知道API暴露的端点是什么?在这些端点上支持的操作是什么?它们应该通过哪些参数?它们会回来什么?使用哪些身份验证方法?要回答这些问题,记录API非常重要。如果您希望API被食用并适当使用。要了解有关 Swagger 的更多信息,请检查 Swagger -javatpoint -javatpoint and Swagger-github repo

  1. @apimodel - 提供有关Swagger模型的其他信息。 Swagger-core在整个API内省中根据对它们的引用来构建模型定义。 @apimodel允许您从简单的描述或名称更改为多态性的定义来操纵模型的元数据。


  2. @valid @Validated 注释 - 在春季,我们使用JSR -303的 @Valid andotation 用方法级验证。我们还使用它来标记成员属性进行验证。但是,此注释不支持组验证

    组有助于限制验证期间应用的约束。一个特殊的用例是UI向导。在第一步中,我们可能有一定的字段。在随后的步骤中,可能还有另一组属于同一豆。因此,我们需要在每个步骤中对这些有限的字段应用约束,但是@Valid不支持这一点。

  • 在这种情况下,对于组级别,我们必须使用Spring的 @Validated ,它是 JSR-303的@Valid 的变体。这是在方法级别使用的。对于标记成员属性,我们继续使用 @Valid 注释。

5什么用:

@ApiModelProperty(required = true, value = "")
@NotNull
  • @apimodelproperty - 在Swagger中,这增加并操纵了模型属性的数据。 @apimodelproperty允许控制特定于特定于允许的值和其他注释。如果您想在某些情况下隐藏该属性,它还提供其他过滤属性。
  • 必需参数指定是否需要参数。 value 参数定义了此属性的简要说明。

  • @nonnull 是一个常见的弹簧注释,以声明注释元素不能为空。它表示参数,字段或方法返回值永远不会为null。这是标记注释,它没有特定的属性。

6什么是 HashCode()方法实际在做什么?

public int hashCode() {
    return Objects.hash(name, number, typeId, taxRateId);
}

HashCode方法是一种内置方法,它返回输入值的整数哈希值。要正确理解 hashcode() equals()使用示例,请查看 hashcode()> hashcode() java方法“ rel =“ nofollow noreferrer”> java中的hashcode方法是什么? - 教育

建议,

如果您没有基础知识,则必须学习Java,这是如此困难。检查以下资源链接以学习Java和Spring Boot。

学习java

  1. 笔记 - Learn Java -Jakob Jenkov
  2. videos- videos- ://www.youtube.com/watch?v = ejaq209nffy&amp; list = plgrdmo4rogcolr -f9ganlyz6ganlyz6o3f_n6wiq“ rel =“ nofollow noreferrer”>学习java-学习java-通过java指南

学习春季启动

  1. //www.javatpoint.com/spring-boot-tutorial“ rel =“ nofollow noreferrer”> Learn Springboot -javatpoint
  2. 视频 - 学习Springboot -Java Guides

I will try to make this very simple and take you step by step

1. What are these imports for?:

import com.fasterxml.jackson.annotation.JsonProperty;

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.

3 Why we use class names in methods? such as:

public LedgerAccountRequestDto taxRateId(String taxRateId) {
    this.taxRateId = taxRateId;
    return this;
}

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.

4 What is the use of:

 @ApiModel(description = "transaction request")
 @Validated**

@ApiModel is a Swagger annotation.

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

  1. @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.

  2. @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);
}

The hashCode method is an inbuilt method that returns the integer hashed value of the input value. To properly understand hashCode() and equals() using examples, check out HashCode() in Java - scaler.com and also What is the hashCode method in Java? - educative.io

ADVICE

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

  1. Notes - Learn Java - By Jakob Jenkov
  2. Videos - Learn Java - By Java Guides

Learn Spring Boot

  1. Notes - Learn SpringBoot - By Javatpoint
  2. Videos - Learn SpringBoot - By Java Guides
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文