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

Hi, family, I’m bug bug, here I go again. Today we are going to talk about something. OK, let’s continue with the SpringBoot Zero-basics tutorial series. Help beginners better entry!

It has good teaching value. I hope you can gain something from this article. I suggest you collect it first and then read it.

If you think the article is good, you are welcome to like it, bookmark it, comment on it, and share it with us. Remember to give the bug bacteria a one-button three-link ~~

Ok, let’s start the main body of this issue.

One, foreword

To study the content of the first four periods, we calculate already half jio set foot in the door, from project framework built to yaml configuration project start to environment dynamic switch to stater is introduced, in fact, we have to springboot had certain basis, the next will really step into practice, but before the actual combat, we need to do a thing, That is familiar with springboot commonly used annotations, which have twice the result with half the effort in the future project practice. You have to study hard

We all know that SpringBoot is created by pure Java code, no longer need to configure complex CONFIGURATION files such as XML, in the configuration can also enjoy the benefits brought by the object, type safety provides good support for reconstruction, reduce complex configuration files at the same time can enjoy the functions provided by the springIoC container. In fact, ah, there are these convenience, largely attributed to annotations credit, that first take a look, the basic common annotations have those ~

2, Spring Boot common annotations

Ps: Because there are too many annotations, friends can use CTRL +F to search oh.Copy the code
  • @SpringBootApplication

This Configuration is equivalent to @Configuration, @EnableAutoConfiguration, and @ComponentScan.

  • @ImportAutoConfiguration

Import a configuration class. This class is used for testing. In normal cases, @enableAutoConfiguration is preferred.

  • @EnableAutoConfiguration 

Automatic configuration.

  • @SpringBootConfiguration

This annotation is actually an @Configuration that identifies the startup class as a Configuration class.

  • @ComponentScan

Component scanning, which automatically discovers and assembles beans.

  • @Component

It can be used with CommandLineRunner to perform some basic tasks after the program is started.

  • @RestController

@controller and @responseBody, indicating that this is a Controller bean and that the return value of the function is inserted directly into the body of the HTTP response. It is a REST-style Controller.

  • @ResponseBody

The return result of this method is directly written to the HTTP Response body. It is usually used to obtain data asynchronously and build RESTful apis. If @requestMapping is used, the return value is usually interpreted as a jump path. If @responseBody is added, the return value is not interpreted as a jump path and is written directly to the HTTP Response Body. So if you get json data asynchronously, and you add @responseBody, it will return json data directly. This annotation is typically used in conjunction with @requestMapping

  • @RequestMapping

Provides routing information responsible for mapping urls to specific functions in the Controller.

  • @Autowired

Automatically import dependent beans.

  • @Inject

Equivalent to the default @autowired, but without the required attribute;

  • @PathVariable

Get parameters.

@JsonBackReference

Solve the nested external chain problem.

  • @Service

Typically used to modify components in the Service layer.

  • @Bean

Using the @bean annotation method is equivalent to configuring beans in XML.

  • @Value

Inject the value of the Spring Boot Application.properties configured property.

  • @Resource

@ the Resource (name = “name”, type = “type”); Without parentheses, byName is the default. Same thing with @autowired.

Jpa notes

  • @Entity,@Table(name="")

Indicates that this is an entity class. These two annotations are usually used together, but @table can be omitted if the Table name is the same as the entity class name

  • @MappedSuperClass

For an entity that is identified as a parent class. Attribute subclasses of the parent class can be inherited.

  • @NoRepositoryBean

Normally used as a repository for the parent class, spring does not instantiate the repository with this annotation

  • @Column

If the field name is the same as the column name, it can be omitted.

  • @Id

Represents the primary key of the property.

  • @ GeneratedValue (strategy = GenerationType SEQUENCE, the generator = "repair_seq")

Indicates that the primary key generation policy is SEQUENCE (Auto, IDENTITY, or native). Auto indicates that the service can be switched among multiple databases. The sequence name is REPAIR_SEq

  • @sequenceGeneretor (Name = "REPAIR_SEQ", sequenceName = "SEQ_repair", allocationSize = 1)

Name is the name of sequence, so that sequenceName is the name of the database sequence. The two names can be the same.

  • @Transient

Indicates that this property is not a mapping to a field of a database table and will be ignored by the ORM framework. If a property is not a field mapping of a database table, it must be marked as @TRANSIENT; otherwise, the ORM framework defaults to annotating it as @BASIC.

  • @Basic(fetch=FetchType.LAZY)

The tag can specify how entity attributes are loaded.

  • @JsonIgnore

Some properties in the Java bean are ignored during JSON serialization, affecting both serialization and deserialization.

  • @ JoinColumn loginId (name = "")

One-to-one: a foreign key in this table that points to another table. One-to-many: another table points to the foreign key of this table.

  • @OneToOne、@OneToMany、@ManyToOne

Correspond to one-to-one, one-to-many, many-to-one in the Hibernate configuration file.

Lombok notes

  • @Setter:

Annotation on attributes; Provide the setting method for the property.

  • @Getter:

Annotation on attributes; Provide getting methods for properties.

  • @Data:

Annotation on class; Provides getting and setting methods for all attributes of a class, as well as equals, canEqual, hashCode, and toString methods.

  • @Log4j2

Annotation on class; Provide the class with a log4j log object with the property log, similar to the @log4j annotation.

  • @NoArgsConstructor:

Annotation on class; Provides a constructor with no arguments for the class.

  • @AllArgsConstructor:

Annotation on class; Provide a full-parameter constructor for the class.

  • @EqualsAndHashCode:

By default, all non-transient and non-static fields are used to generate equals and Hascode methods, and you can specify which attributes to use.

  • @toString:

Generates the toString method, which by default prints the class name, all the attributes, and the attributes are printed in order, separated by commas.

  • @NoArgsConstructor.@RequiredArgsConstructor and @AllArgsConstructor:

No-parameter constructors, partial parameter constructors, full parameter constructors, when we need to overload more than one constructor, we have to write it by hand.

  • @NonNull:

Annotations on properties, if annotated, must not be Null.

  • @val:

Annotation on the property, if annotated, is set to final type, can see the source of the comments know.

5. Transaction annotations

  • @Transactional

In Spring, there are two implementations of transactions, programmatic and declarative.

Programmatic transaction: use programmatic transaction TransationTemplate PlatformTransactionManager or directly use the bottom. For programmatic transactions, Spring recommends using TransationTemplate.

Declarative transaction: based on AOP, its essence is to intercept method before and after, and then the target method before you begin to create or join a transaction, the execution of the target method according to the execution situation after commit or rollback transaction through @ Transactional affairs operation, could be more efficient and simple. Recommended.

Global exception handling

  • @ ControllerAdvice:

Contains @ Component. It can be scanned. Uniformly handle exceptions.

  • @ExceptionHandler (exception.class) :

Method to execute the following method when the exception is encountered.

7. SpringMVC annotations

  • @ RequestMapping:

@requestMapping (/path) : Indicates that the controller processes all UR L requests of /path. RequestMapping is an annotation to handle request address mapping, which can be used on a class or method.

  • @ RequestParam:

Used in front of method arguments.

  • @PathVariable:

Path variable. The arguments must be the same as the names in braces.

. .

OK, that’s all for this episode. If you have any questions, feel free to comment in the comments section. See you next time.

Eight, hot article recommendation:

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Springboot< a >: zero basic entry Springboot and IDEA setup

Springboot< 2 >: zero basic entry yamL, properties configuration file introduction and actual use

Springboot< three >: multi-environment switch, profile example demonstration

Springboot< four >: Introduction to stater teaching

Springboot< 5 >: common annotations for Springboot

Springboot< six >:mysql configuration and database query, implement add, delete, change and check

Springboot< seven >: Mybatis -plus entry and actual use to achieve the increase, deletion, change and check

Springboot< 8 >: Mybatis -plus conditional constructor user manual

Springboot< 9 >: Mybatis – Plus custom SQL zero-based teaching

Springboot< ten >: Mybatis XML mapping file >, <= and other special symbols written

. .

If you want to learn more, you can pay attention to the bug bug column “SpringBoot Zero-based Introduction”, from scratch, from zero to one! Hope I can help you.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Be who you want to be, there is no time limit, you can start whenever you want,

You can change from now on, or you can stay the same. There are no rules, and you can be the best version of yourself.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

If this article has been helpful, please put your thumb in the bottom left corner of the article. (# ^. ^ #);

If you like the articles shared by Bug bug, please send bug bug a note! The danjun ‘ᴗ, you guys will have a cameo appearance with you.

If you have any questions about this article, please leave a comment below or join the group [Group number: 708072830].

In view of limited personal experience, all views and technical research points, if you have any objection, please directly reply to participate in the discussion (no offensive comments, thank you);

Copyright notice: This article is the blogger’s original article, reprint please attach the original source link and this article statement, all rights reserved, piracy will investigate! (* ^ del ^ *)