In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you what are the common notes on SpringBoot. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
SpringBoot comments
@ SpringBootApplication: enable the core annotation of SpringBoot automatic configuration, which is equivalent to the simultaneous use of @ Configuration,@EnableAutoConfiguration and @ ComponentScan annotations.
@ EnableAutoConfiguration:SpringBoot auto configuration enables annotations. When enabled, an attempt is made to automatically configure the relevant components based on jar dependencies added to the classpath. It is one of the core annotations of Spring Boot auto-configuration mechanism.
The @ ConditionalOnXXXX:Spring Boot decides whether or not to load the specified Bean based on whether a particular condition is met, based on the derivative annotations extended by @ Conditional. For example, extended annotations include: @ ConditionalOnBean, @ ConditionalOnClass, and so on.
ConfigurationProperties: based on type-safe property configuration injection, you can associate a properties property with a Bean and its properties, thus implementing type-safe configuration.
Basic comments on Spring
Conditional: one of the most widely used annotations in Spring Boot, it can decide whether or not to load a specified Bean based on whether a particular condition is met.
@ ComponentScan: this annotation scans all configuration classes under the package in which the class resides by default, which is equivalent to context:component-scan in xml. If you scan a class with @ Component, @ Controller, @ Service, and so on, register it as Bean, and you can automatically collect all Spring components, including the @ Configuration class. Spring Boot scans classes that use the above annotations under the package where the startup class is located and under the subpackage.
Configuration: used to define a configuration class that replaces the xml configuration file. The annotated class contains one or more methods annotated by @ Bean.
Profile: provides a way to isolate application configurations and let them take effect only in specific environments. Any @ Component or @ Configuration can be marked with @ Profile, limiting the timing of loading it.
@ Import: used to import other configuration classes, just like the import tag configured by xml, allowing classes annotated by @ Configuration to be introduced through it (java config). Spring4.2 can also import ordinary Java and declare it as a bean later.
ImportResource: used to import a traditional xml configuration file.
Autowired: automatically import dependent bean, mark class member variables, methods, and constructors, and complete automatic assembly. The function is similar to @ Resource, but it is automatically assembled by type by default, and @ Qualifier is required if you need to assemble by name.
@ Service: commonly used to label business layer components, which means to define a bean and automatically instantiate a bean with lowercase letters according to the class name of bean.
Component: generally refers to components. You can use this annotation to annotate components when they are difficult to classify.
Repository: persistence layer component, used to annotate the data access component, that is, the DAO component.
@ Bean: the @ Bean annotation method is equivalent to the bean configured in XML.
Value: assign the value corresponding to key in the configuration file to its annotated attribute.
Inject: is the specification in JSR330 and is equivalent to the default @ Autowired. For automatic assembly according to type, if you need to assemble by name, you need to match @ Named.
Bean: the equivalent of XML, above the method, not the class, which means to generate a bean and give it to spring to manage.
AutoWired: automatically imports dependent bean. ByType mode. The configured Bean is used to complete the assembly of properties and methods. It can mark class member variables, methods and constructors and complete the work of automatic assembly. When (required=false) is added, an error is not reported even if the bean is not found.
@ Qualifier: when there are multiple Bean of the same type, you can specify it with @ Qualifier ("name"). Used with @ Autowired. The @ Qualifier qualifying descriptor can be injected based on name, but has more fine-grained control over how candidates are selected.
The implementation of the @ Resource:JSR250 specification, which automatically assembles by name, usually specifies a name attribute.
@ JsonBackReference:jackson framework annotations to solve the problem of nested outer chains.
PropertySource: loads the specified configuration file, usually a custom properties file.
Spring Web comments on which Zhengzhou abortion Hospital has a good http://mobile.zhongyuan120.com/
@ ResponseBody: indicates that the returned result of this method is directly written into HTTP response body, which is generally used when obtaining data or interface interaction asynchronously, and is used to build the api of RESTful. Normally, the returned class is returned to the client in the form of a Json string.
Controller: the decorated class is instantiated and injected into the Spring IOC container. The function of semantics means that the class acts as a Controller. Generally, this class (controller) is responsible for forwarding URL requests sent by users to the corresponding service interface (service layer).
RestController: used to annotate the control layer components, a collection of @ ResponseBody and @ Controller.
RequestMapping: provides routing information and is responsible for mapping URL to specific functions in Controller.
GetMapping: is a combined annotation and is an abbreviation for @ RequestMapping (method=RequestMethod.GET).
@ PostMapping is a combined annotation and is an abbreviation for @ RequestMapping (method=RequestMethod.POST).
A new feature of @ PathVariable:spring3.0 to receive the value of placeholders in the request path. The placeholder parameter in URL can be bound to the input parameter of the controller processing method through @ PathVariable: the {xxx} placeholder in URL can be bound to the input parameter of the action method through @ PathVariable ("xxx").
RequestParam: bind the request parameter to the controller's method parameter.
ControllerAdvice: an enhanced Controller commonly used for global exception handling, global data binding, global data preprocessing, and so on.
@ ExceptionHandler: used in conjunction with @ ControllerAdvice for unified exception handling.
JPA comments
Entity: indicates that this is an entity class, such as the entity class UserEntity, and the default table name in the corresponding database is user_entity. Generally used in conjunction with @ Table, @ Table can be omitted if the table name and entity class name are the same.
@ Table: you need to use @ Table annotation when the name of the entity class is different from the name of the database table it maps to. This annotation is used side by side with the @ Entity annotation and is placed in front of the entity class declaration statement. It can be written on a separate statement line or in the same line as the declaration statement.
@ MappedSuperClass: the annotation is used on the parent class. The identified class indicates that it cannot be mapped to a database table, and the identified class can no longer use @ Entity or @ Table annotations.
@ NoRepositoryBean: generally used as the repository of the parent class, tell JPA not to create a bean object for the corresponding interface and annotate the class with @ NoRepositoryBean.
@ Column: used to identify the correspondence between the attribute in the entity class and the field in the data table. If the field name is the same as the column name, it can be omitted.
Id: indicates that the property is the primary key.
GeneratedValue: provides a generation policy for entities to generate primary keys with unique identities. Primary key generation strategies include sequence,Auto, IDENTITY, native, etc. Auto means you can switch between multiple databases.
Transient: indicates that the attribute is not mapped to the fields of the database table and is ignored by the ORM framework.
JsonIgnore: the effect is that some attributes in Java bean are ignored when json serialization, and both serialization and deserialization are affected.
JoinColumn: used to specify the column fields in the database table associated with the entity or collection of entities being operated on. One-to-one, the foreign key in this table that points to another table; one-to-many, and the other table points to the foreign key in this table.
@ OneToOne, @ OneToMany, @ ManyToOne: correspond to one-to-one, one-to-many, many-to-one in the hibernate configuration file.
Thank you for reading! This is the end of this article on "what are the common notes on SpringBoot?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.