spring boot combing comment

First, notes (annotations) list

@SpringBootApplication: contains @ ComponentScan, @ Configuration and @EnableAutoConfiguration comment. Which @ComponentScan scan to make spring Boot Configuration class and add it to the program context.

@Configuration:  equivalent to the spring XML configuration file; the use of Java code can check the type of security.

@EnableAutoConfiguration:  automatic configuration.

@ComponentScan:  component scans automatic discovery and assembly of some Bean.

@Component: can be used with CommandLineRunner used to perform some basic tasks after the program starts.

@RestController: is @Controller @ResponseBody and the collection, the controller indicates this is the bean, and the return value of the function is filled directly into the body of the HTTP response, the controller is REST style.

@Autowired: automatic import.

@PathVariable: acquisition parameters.

@JsonBackReference: to solve the problem of nested outside the chain.

@RepositoryRestResourcepublic: with the spring-boot-starter-data- rest used.


 

 

Second, notes (annotations) Comments

@SpringBootApplication: Affirming let spring boot automatically makes the necessary configuration to the program, this configuration is equivalent to: @Configuration, @ EnableAutoConfiguration and @ComponentScan three configurations.

@ResponseBody: indicates that the method returns the result directly written HTTP response body is generally used in the asynchronous data acquired for constructing the api RESTful. @RequestMapping after use, the return value is typically resolved as the jump path and, with the results returned @responsebody not be interpreted as the jump path, but directly written in the HTTP response body. Such as asynchronous get json data, after adding @responsebody, it will return json data directly. The Notes will generally be used in conjunction with @RequestMapping.

@Controller: used to define the controller class, the spring project by a controller responsible for forwarding URL request sent by a user to the corresponding service interface (service layer), generally in the annotation class annotated with the conventional method requires @RequestMapping .

@RestController: a labeling component control layer (e.g., the action struts), @ ResponseBody @Controller and the collection.

@RequestMapping: provides routing information, URL mapping to the Controller responsible for specific functions.

@EnableAutoConfiguration: Spring the Boot automatic configuration (auto-configuration): attempts to automatically configure your Spring application according to jar you depend added. For example, if your classpath under HSQLDB, and you do not have to manually configure any database connections beans, then we will automatically configure a type of memory (in-memory) database. "

You can add notes to a @EnableAutoConfiguration or @SpringBootApplication @Configuration class up to select automatic configuration. If you find that a particular application automatically configures classes you do not want, you can use negative attributes @EnableAutoConfiguration comment to disable them.

@ComponentScan: indicates the type of automatic discovery scanning assembly. Personal understanding is equivalent to, if the class has to scan these annotations @ Component, @ Controller, @ Service, etc., and registered as Bean, Spring can automatically collect all the components, including @Configuration class.

We often use @ComponentScan annotation search beans, combined with @Autowired notes import. Spring can automatically collect all the components, including @Configuration class. We often use @ComponentScan annotation search beans, combined with @Autowired notes import.

If no words, Spring Boot will start scanning the next class pack and use the @ Service, @ Repository annotation and other sub-package in the class lies.

@Configuration: equivalent to the traditional xml configuration file, if you need to use some third-party library xml file, still recommended as the main class configuration items by @Configuration class - can be used to load xml configuration file @ImportResource comment.

@Import: used to introduce other configuration class.

@ImportResource: used to load xml configuration file.

@Autowired: automatically import dependent bean

@Service: General assembly of the service layer for modifying

@Repository: Use @Repository annotation can ensure DAO abnormal or repositories provide translation, this annotation modified or repositories DAO class will be found and configured ComponetScan, also do not need to provide XML configuration items for them.

@Bean: with @Bean bean XML tagging method is equivalent to the configuration.

@Value: injecting value Spring boot application.properties configuration attributes.

@Inject: equivalent to the default @Autowired, but there is no required attributes;

@Component: refers to the components when the components are classified bad, we can use this annotation to mark.

@Bean: equivalent to the above XML, on the approach, rather than a class, meaning that produces a bean, and manage to spring.

@AutoWired: automatically import dependent bean. byType way. Bean configured to make use, completed properties, assembly method, it can be labeled class fields, methods and constructors, the completion of the automatic assembly. When coupled with (required = false), even if can not find the bean is not an error.

@Qualifier: when a plurality of the same type of Bean, can be specified @Qualifier ( "name"). Used in conjunction with @Autowired. In addition to descriptors defining @Qualifier implanting by name, but can be more fine-grained control how the selected candidate

@Resource (name = "name", type = "type"): there is no content within the parentheses, the default byName. A similar thing with @Autowired dry.


 

 

Three, JPA annotations

@Entity: @Table (name = ""): indicates that this is an entity class. Both generally used jpa annotations using a general, but if the table name and the name of the entity, then the same class, @ Table may be omitted

@MappedSuperClass: used in determining whether the parent entity. Properties sub-class of the parent class can be inherited.

@NoRepositoryBean: generally used as the parent class repository, this annotation, spring not to instantiate the repository.

@Column: field name and column names the same, it may be omitted.

@Id: indicates that the primary key attribute.

@GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "repair_seq"): represents a primary key generation strategy is sequence (may be Auto, IDENTITY, native, etc., represents Auto switch between a plurality of databases), the name of the specified sequence is repair_seq.

@SequenceGeneretor (name = "repair_seq", sequenceName = "seq_repair", allocationSize =. 1): name is the name of the sequence to use, the name of the database sequence is sequenceName, two names may coincide.

@Transient: indicates that the property is not mapped to a field in a database table, ORM framework will ignore the attributes. If a property is not a field mapping database tables, be sure to mark it as @Transient, otherwise, ORM framework annotated as its default @Basic. @Basic (fetch = FetchType.LAZY): loading the entity may specify tag attributes

@JsonIgnore: the role is json serialized Java bean will ignore some of the properties, serialization and de-serialization are affected.

@JoinColumn (name = "loginId") : one: This table to the foreign key in another table. Many: foreign key to another table in this table.

@ OneToOne, @ OneToMany, @ ManyToOne : corresponds to hibernate configuration file one to one, one to many, many to one.


 

 

Four, springMVC related notes

@RequestMapping: @RequestMapping ( "/ path") indicates that the controller handles all "/ path" of the request UR L. RequestMapping is a process for annotation request address mapping, it can be used for class or method.
For the class, all the methods in response to the request class are represented in the address as the parent path. This note has six attributes:

  • params: Specifies the request must contain certain parameter values, before allowing the processing method.

  • headers: Specifies the request must contain certain specified header value, in order for this method to process the request.

  • value: Specifies the physical address of the request, can be specified address mode URI Template

  • method: method specifies the type of request, GET, POST, PUT, DELETE, etc.

  • consumes: submit a request specifying process of the content type (Content-Type), such as application / json, text / html;

  • produces: content type of the returned only when the head (the Accept) The request includes a request type specifies the type will return to

@RequestParam: used in front of the method parameters.

@PathVariable: path variable.


 

Fifth, global exception handler

@ControllerAdvice: contains @Component. It can be scanned. Unified handle exceptions.

@ExceptionHandler (Exception.class): represents this anomaly encountered on the implementation of the following methods used in the above methods.


 

Guess you like

Origin www.cnblogs.com/21-Gram/p/11906668.html