Annotations @SpringBootApplication contains @ComponentScan, @Configuration, and @EnableAutoConfiguration annotations. @ComponentScan tells Spring Boot to scan the Configuration class and add it to the application context. @Configuration is equivalent to spring’s XML Configuration file; You can check type safety using Java code. @enableAutoConfiguration Automatic configuration. @componentscan ComponentScan to automatically discover and assemble some beans. The @Component can be used in conjunction with CommandLineRunner to perform some basic tasks after the program is started. The @RestController annotation is a combination of @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, which is a REST-style Controller. @autoWired Automatically imports. @pathvariable gets arguments. @jsonBackReference resolves nested external links. @ RepositoryRestResourcepublic with spring – the boot – starter – data – rest. Annotations @SpringBootApplication: specifies that SpringBoot automatically performs the required configuration for the program. @Configuration, @EnableAutoConfiguration, and @ComponentScan are configured.

package com.example.myproject; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}

ResponseBody: indicates that the return result of this method is directly written to the HTTP response body. This method is 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. ResponseBody public String test(){return “OK”; RequestMapping(” /test “) @responseBody public String test(){return “ok”; }

@Controller: Defines the Controller class. In spring projects, the Controller is responsible for forwarding URL requests from the user to the corresponding service layer. Usually this annotation is in the class, and usually methods need to be annotated with @requestMapping. Sample code:

@controller @requestMapping (” /demoInfo “) PublicClass DemoController {@autoWired private DemoInfoService demoInfoService;

@RequestMapping(“/hello”) public String hello(Map

map){ System.out.println(“DemoController.hello()”); map.put(“hello”,”from TemplateController.helloHtml”); // The hello.html or hello.ftl template will be used for rendering. }}
,object>

@restController: A collection of annotated control-layer components such as actions in Struts, @responseBody, and @Controller. Sample code:

package com.kfit.demo.web;

import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;

@restController@requestMapping (” /demoInfo2 “) publicClass DemoController2 {

@RequestMapping(“/test”) public String test(){ return”ok”; }}

@requestMapping: Provides routing information that maps urls to specific functions in the Controller. @enableAutoConfiguration: Spring Boot Auto-configuration: Try to automatically configure your Spring application based on the JAR dependencies you add. For example, if HSQLDB exists in your CLASspath and you don’t manually configure any database connection Beans, we will automatically configure an in-memory database. You can add the @EnableAutoConfiguration or @SpringBootApplication annotation to an @Configuration class to select automatic Configuration. If you find specific auto-configuration classes applied that you don’t want, you can disable them using the exclusion attribute of the @enableAutoConfiguration annotation. @ComponentScan: automatically discovers scanned components for this class. If you scan a class with @Component, @Controller, @Service, etc., and register it as a Bean, you can automatically collect all Spring components, including the @Configuration class. We often use the @ComponentScan annotation to search for Beans, combined with the @AutoWired annotation to import. All Spring components can be collected automatically, including the @Configuration class. We often use the @ComponentScan annotation to search for Beans, combined with the @AutoWired annotation to import. If not, Spring Boot scans for classes that use @service, @repository annotations in the Boot package and its children. @Configuration: Equivalent to a traditional XML Configuration file. If some third-party libraries require an XML file, it is recommended that the @Configuration class be used as the main Configuration class of the project — the XML Configuration file can be loaded using the @ImportResource annotation. @import: Used to Import other configuration classes. ImportResource: Used to load XML configuration files. @autowired: automatically import dependent beans @service: generally used to modify components of the Service layer @repository: Using the @Repository annotation ensures that DAO or Repositories provides an exception translation. The DAO or Repositories class modified by this annotation will be found and configured by ComponetScan without providing an XML configuration entry for them. @beans: Annotating @beans is equivalent to beans configured in XML. @value: Injects the Value of the Spring Boot Application. properties configured property. Example code: @value (Value = “#{message}”) private String message;

Inject @inject: Equivalent to the default @autowired, but without the required attribute; @Component: Component annotation. This annotation can be used when components are difficult to categorize. @bean: equivalent to XML, on top of a method, not a class, meaning to generate a Bean and hand it over to Spring to manage. AutoWired: Automatically import dependent beans. ByType way. The configured Bean is used to complete the assembly of attributes and methods. It can annotate class member variables, methods and constructors to complete the work of automatic assembly. When (required=false) is added, no error is reported even if the bean is not found. @qualifier: When there are multiple beans of the same type, you can specify it as @qualifier (” name “). Used with @autowired. In addition to being injected by name, the @qualifier Qualifier provides more fine-grained control over how candidates are selected, as follows: @autoWired @Qualifier(value = “demoInfoService”) private demoInfoService demoInfoService;

@resource (name= “name”,type= “type”) : byName is the default if there is no parentheses. Same thing with @autowired. JPA annotation @entity: @table (name= “) : indicates that this is an Entity class. These two annotations are generally used together, but @table can omit @mappedsuperClass if the Table name is the same as the entity class name: 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. With this annotation, Spring will not instantiate the repository. @column: If the field name is the same as the Column name, it can be omitted. @id: indicates that the attribute is the primary key. @ 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 attribute 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) : this flag can specify the loading method of entity attributes. @jsonIgnore: This flag will ignore some attributes in Java beans during JSON serialization. @joinColumn (name= “loginId”) : One-to-one: indicates the foreign key that points to another table in this table. One-to-many: another table points to the foreign key of this table. @onetoone, @onetomany, @manytoone: Corresponds to one-to-one, one-to-many, many-to-one in hibernate configuration files. @requestMapping: @requestMapping (” /path “) specifies that the controller processes all UR L requests for “/path”. RequestMapping is an annotation to handle request address mapping, which can be used on a class or method. Used on a class, this address is used as the parent path for all methods in the class that respond to requests. This annotation has six attributes: params: Specifies that the request must contain some parameter values for the method to process. Headers: Specifies that the request must contain some specified header value before the method can process the request. Value: specifies the actual address for the request. The address can be a URI Template mode. Method: specifies the method Type of the requests. Such as application/json, text/HTML. Produces: Specifies the content type returned. Returns @requestParam only if the specified type is in the (Accept) type in the Request header. @requestParam String a =request.getParameter(” a “). @pathvariable: PathVariable. For example, RequestMapping(user/get/ MAC /{macAddress}) public String getByMacAddress(@pathVariable String macAddress){//do something; } arguments should be the same as the names in braces.

@ControllerAdvice: contains @Component. It can be scanned. Uniformly handle exceptions. ExceptionHandler (exception.class) : Used above a method to indicate that the following method is executed when this Exception is encountered.

Thank you for your attention!!