spring series annotation + jpa annotation

1. Spring boot annotation
@SpringBootApplication: Contains @ComponentScan, @Configuration and @EnableAutoConfiguration annotations. Where @ComponentScan lets spring Boot scan the Configuration class and add it to the program context.

@Configuration is equivalent to Spring's XML configuration file; type safety can be checked using Java code.

@EnableAutoConfiguration Automatic configuration.

@ComponentScan component scanning, which can automatically discover and assemble some beans.

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

The @RestController annotation is a collection of @Controller and @ResponseBody, indicating that this is a controller bean, and it is a REST-style controller that directly fills the return value of the function into the HTTP response body.

@Autowired is automatically imported.

@PathVariable gets parameters.

@JsonBackReference solves the problem of nested external links.

@RepositoryRestResourcepublic is used with spring-boot-starter-data-rest.

Detailed explanation

@SpringBootApplication: Declare that spring boot automatically configures the program with the necessary configuration. This configuration is equivalent to three configurations: @Configuration, @EnableAutoConfiguration and @ComponentScan.

复制代码
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 into the HTTP response body, which is generally used when acquiring data asynchronously and is used to build a RESTful api. After using @RequestMapping, the return value is usually parsed as a jump path. After adding @responsebody, the return result will not be parsed as a jump path, but written directly into the HTTP response body. For example, asynchronously obtaining json data and adding @responsebody will directly return json data. This annotation is generally used in conjunction with @RequestMapping. Sample code:

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

@Controller: used to define the controller class. In the spring project, the controller is responsible for forwarding the URL request sent by the user to the corresponding service interface (service layer). Generally, this annotation is in the class, and the method usually needs to cooperate with the annotation @RequestMapping . Sample code:

复制代码
@Controller
@RequestMapping(“/demoInfo”)
publicclass DemoController {
@Autowired
private DemoInfoService demoInfoService;

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

Related Posts