This is the 21st day of my participation in Gwen Challenge
1. @ SpringBootApplication
This annotation is the most important core annotation of the SpringBoot framework. It is used on the main class to define the start of SpringBoot projects and the start of various capabilities. It is used to identify the SpringBoot project, which is usually inserted in the Main class of the Web layer.
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public static void main(String[] args) {
SpringApplication.run(TestWebApplication.class,args);
}
Copy the code
2, @ MapperScan
Add @mapper to the interface class, which generates the corresponding interface implementation class after compilation.
Added to the launcher class, it specifies the package in which the interface to become the implementation class belongs, and all interfaces under the package will generate the corresponding implementation class when compiled.
Add to DataSourceConfig, specify data source, configuration file, etc.
3, @ Configuration
The definition of the configuration class, indicating that the object is the source of the Bean definition. For example, in the configuration file for mysql, Redis, and other middleware, the Bean can be found through this annotation.
4, @ ComponentScan
Component scanning. All ComponentScan does is tell Spring where to find beans.
Tell Spring which annotated classes of Packages will be automatically scanned by Spring and loaded into the bean container.
The @ComponentScan annotation will by default assemble classes that identify the @Controller, @Service, @Repository, and @Component annotations into the Spring container.
5, @ the Repository
On the persistence layer.
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.
@Repository(value=”testDao”)
This annotation tells Spring to create an instance of TestDaoImpl named “testDao”.
When the Service needs to use a TestDaoImpl instance created by Spring named “testDao”, it can use the @resource (name = “testDao”) annotation to tell Spring, Spring simply injects the testDao created into the Service.
6, @ Service
Annotations belong to the business logic layer, service or Manager layer, and modify files at the Service layer.
@Service public class UserService {}Copy the code
7, @ RestController
So, to return json, you need @ResponseBody and @Controller together.
So @restController is a combination annotation of @responseBody and @Controller.
8, @ ResponseBody
RequestMapping (@responseBody, @responseBody, @responseBody, @responseBody, @responseBody);
9, @ Component
The @Component annotation is at the top of the controller, service, and repository, and is a common stereotype annotation for any Spring-managed Component, which means that if you want to register classes in an application context, you can use the @Component annotation to do so.
10, @ Bean
@Bean is a method-level annotation that is used primarily in the @Configuration annotation class, but also in the @Component annotation class. The id of the added bean is the method name, which means that a bean is generated and handed over to Spring for management.
11, the @autowired
It can annotate class member variables, methods and constructors to complete the work of automatic assembly. Eliminate set, get methods by using @autowired.
12, @ the Qualifier
When you need to inject Java beans automatically, an error is reported if you inject an interface that has multiple implementation classes.
The solution is to add @Service(” alias “) on the implementation class and @Qualifier(” alias “) and @AutoWired annotations on the injection interface.
Take a look at the source:
public @interface Qualifier {
String value(a) default "";
}
Copy the code
13, @ RequestMapping
Handles the mapping of the requested address
For classes and methods, the request address on a class is the parent address of the request address on a method. You typically set the categorization of all interfaces in the file on the class. For example, the following example shows that this class contains the Test interface.
@RequestMapping(value = "/test")
@RestController
public class TestController {
@RequestMapping(value = "/getList", method = RequestMethod.POST)
public Result getList(@RequestBody TestQuery query) {
return null; }}Copy the code
@requestParam and @requestBody
Used in front of a parameter to indicate the method request body.
public Result getList(@RequestBody TestQuery query)
Copy the code
@RequestParam String a =request.getParameter('a').Copy the code
15, @ PathVariable
Gets the parameters in the path
16, @ Profiles
This annotation, in conjunction with @Configuration, allows you to specify the Configuration of different profiles using Java code, either on classes or on @Bean methods.
17, @ ConfigurationProperties
Read properties from a configuration file, like a datasource file.
@ConfigurationProperties(prefix = "test.data")
public class DataSourceProperty {
/** * database address */
private String url;
/** * account */
privateString name; } # test.data.url= test.data.name=Copy the code